OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
6 | 6 |
7 #include "include/dart_debugger_api.h" | 7 #include "include/dart_debugger_api.h" |
8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
10 #include "vm/debugger.h" | 10 #include "vm/debugger.h" |
(...skipping 1859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1870 Service::HandleIsolateMessage(isolate, service_msg); | 1870 Service::HandleIsolateMessage(isolate, service_msg); |
1871 handler.HandleNextMessage(); | 1871 handler.HandleNextMessage(); |
1872 EXPECT_STREQ("alpha", handler.msg()); | 1872 EXPECT_STREQ("alpha", handler.msg()); |
1873 service_msg = Eval(lib, "[0, port, ['beta'], [], []]"); | 1873 service_msg = Eval(lib, "[0, port, ['beta'], [], []]"); |
1874 Service::HandleIsolateMessage(isolate, service_msg); | 1874 Service::HandleIsolateMessage(isolate, service_msg); |
1875 handler.HandleNextMessage(); | 1875 handler.HandleNextMessage(); |
1876 EXPECT_STREQ("beta", handler.msg()); | 1876 EXPECT_STREQ("beta", handler.msg()); |
1877 } | 1877 } |
1878 | 1878 |
1879 | 1879 |
| 1880 TEST_CASE(Service_MetricsList) { |
| 1881 const char* kScript = |
| 1882 "import 'dart:profiler';\n" |
| 1883 "var port;\n" // Set to our mock port by C++. |
| 1884 "\n" |
| 1885 "main() {\n" |
| 1886 " var counter = new Counter('hello', 'apple');\n" |
| 1887 " Metrics.add(counter);\n" |
| 1888 " return counter;\n" |
| 1889 "}\n" |
| 1890 ""; |
| 1891 |
| 1892 Isolate* isolate = Isolate::Current(); |
| 1893 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); |
| 1894 EXPECT_VALID(h_lib); |
| 1895 Library& lib = Library::Handle(); |
| 1896 lib ^= Api::UnwrapHandle(h_lib); |
| 1897 EXPECT(!lib.IsNull()); |
| 1898 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); |
| 1899 EXPECT_VALID(result); |
| 1900 |
| 1901 // Build a mock message handler and wrap it in a dart port. |
| 1902 ServiceTestMessageHandler handler; |
| 1903 Dart_Port port_id = PortMap::CreatePort(&handler); |
| 1904 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); |
| 1905 EXPECT_VALID(port); |
| 1906 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); |
| 1907 |
| 1908 Array& service_msg = Array::Handle(); |
| 1909 service_msg = Eval(h_lib, "[0, port, ['metrics'], [], []]"); |
| 1910 Service::HandleIsolateMessage(isolate, service_msg); |
| 1911 handler.HandleNextMessage(); |
| 1912 printf("%s\n", handler.msg()); |
| 1913 // Expect MetricList. |
| 1914 EXPECT_SUBSTRING("\"type\":\"MetricList\"", handler.msg()); |
| 1915 } |
| 1916 |
| 1917 |
| 1918 TEST_CASE(Service_Metric) { |
| 1919 const char* kScript = |
| 1920 "import 'dart:profiler';\n" |
| 1921 "var port;\n" // Set to our mock port by C++. |
| 1922 "\n" |
| 1923 "main() {\n" |
| 1924 " var counter = new Counter('hello', 'apple');\n" |
| 1925 " Metrics.add(counter);\n" |
| 1926 " return counter;\n" |
| 1927 "}\n" |
| 1928 ""; |
| 1929 |
| 1930 Isolate* isolate = Isolate::Current(); |
| 1931 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); |
| 1932 EXPECT_VALID(h_lib); |
| 1933 Library& lib = Library::Handle(); |
| 1934 lib ^= Api::UnwrapHandle(h_lib); |
| 1935 EXPECT(!lib.IsNull()); |
| 1936 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); |
| 1937 EXPECT_VALID(result); |
| 1938 |
| 1939 // Build a mock message handler and wrap it in a dart port. |
| 1940 ServiceTestMessageHandler handler; |
| 1941 Dart_Port port_id = PortMap::CreatePort(&handler); |
| 1942 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); |
| 1943 EXPECT_VALID(port); |
| 1944 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); |
| 1945 |
| 1946 Array& service_msg = Array::Handle(); |
| 1947 service_msg = Eval(h_lib, "[0, port, ['metrics', '0'], [], []]"); |
| 1948 Service::HandleIsolateMessage(isolate, service_msg); |
| 1949 handler.HandleNextMessage(); |
| 1950 |
| 1951 // Expect MetricList. |
| 1952 EXPECT_SUBSTRING("\"type\":\"Counter\"", handler.msg()); |
| 1953 } |
| 1954 |
| 1955 |
1880 // TODO(zra): Remove when tests are ready to enable. | 1956 // TODO(zra): Remove when tests are ready to enable. |
1881 #if !defined(TARGET_ARCH_ARM64) | 1957 #if !defined(TARGET_ARCH_ARM64) |
1882 | 1958 |
1883 TEST_CASE(Service_Profile) { | 1959 TEST_CASE(Service_Profile) { |
1884 const char* kScript = | 1960 const char* kScript = |
1885 "var port;\n" // Set to our mock port by C++. | 1961 "var port;\n" // Set to our mock port by C++. |
1886 "\n" | 1962 "\n" |
1887 "var x = 7;\n" | 1963 "var x = 7;\n" |
1888 "main() {\n" | 1964 "main() {\n" |
1889 " x = x * x;\n" | 1965 " x = x * x;\n" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1922 service_msg = Eval(h_lib, "[0, port, ['profile'], ['tags'], ['hidden']]"); | 1998 service_msg = Eval(h_lib, "[0, port, ['profile'], ['tags'], ['hidden']]"); |
1923 Service::HandleIsolateMessage(isolate, service_msg); | 1999 Service::HandleIsolateMessage(isolate, service_msg); |
1924 handler.HandleNextMessage(); | 2000 handler.HandleNextMessage(); |
1925 // Expect error. | 2001 // Expect error. |
1926 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | 2002 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); |
1927 } | 2003 } |
1928 | 2004 |
1929 #endif // !defined(TARGET_ARCH_ARM64) | 2005 #endif // !defined(TARGET_ARCH_ARM64) |
1930 | 2006 |
1931 } // namespace dart | 2007 } // namespace dart |
OLD | NEW |