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" | |
koda
2014/07/29 15:34:30
Consider using slightly more realistic names to he
| |
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 // Expect MetricList. | |
1913 EXPECT_SUBSTRING("\"type\":\"MetricList\"", handler.msg()); | |
koda
2014/07/29 15:34:30
Check that it contains exactly one member?
Cutch
2014/07/29 18:27:01
Oi, testing this in C++ is going to be painful. Pe
koda
2014/07/29 19:44:13
Please make it a TODO, since I have a feeling ther
Cutch
2014/07/30 00:01:23
Done.
| |
1914 } | |
1915 | |
1916 | |
1917 TEST_CASE(Service_Metric) { | |
1918 const char* kScript = | |
1919 "import 'dart:profiler';\n" | |
1920 "var port;\n" // Set to our mock port by C++. | |
1921 "\n" | |
1922 "main() {\n" | |
1923 " var counter = new Counter('hello', 'apple');\n" | |
1924 " Metrics.add(counter);\n" | |
1925 " return counter;\n" | |
1926 "}\n" | |
1927 ""; | |
1928 | |
1929 Isolate* isolate = Isolate::Current(); | |
1930 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); | |
1931 EXPECT_VALID(h_lib); | |
1932 Library& lib = Library::Handle(); | |
1933 lib ^= Api::UnwrapHandle(h_lib); | |
1934 EXPECT(!lib.IsNull()); | |
1935 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); | |
1936 EXPECT_VALID(result); | |
1937 | |
1938 // Build a mock message handler and wrap it in a dart port. | |
1939 ServiceTestMessageHandler handler; | |
1940 Dart_Port port_id = PortMap::CreatePort(&handler); | |
1941 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); | |
1942 EXPECT_VALID(port); | |
1943 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); | |
1944 | |
1945 Array& service_msg = Array::Handle(); | |
1946 service_msg = Eval(h_lib, "[0, port, ['metrics', '0'], [], []]"); | |
1947 Service::HandleIsolateMessage(isolate, service_msg); | |
1948 handler.HandleNextMessage(); | |
1949 | |
1950 // Expect MetricList. | |
koda
2014/07/29 15:34:30
MetricList -> Counter
Cutch
2014/07/29 18:27:01
Done.
| |
1951 EXPECT_SUBSTRING("\"type\":\"Counter\"", handler.msg()); | |
1952 } | |
1953 | |
1954 | |
1880 // TODO(zra): Remove when tests are ready to enable. | 1955 // TODO(zra): Remove when tests are ready to enable. |
1881 #if !defined(TARGET_ARCH_ARM64) | 1956 #if !defined(TARGET_ARCH_ARM64) |
1882 | 1957 |
1883 TEST_CASE(Service_Profile) { | 1958 TEST_CASE(Service_Profile) { |
1884 const char* kScript = | 1959 const char* kScript = |
1885 "var port;\n" // Set to our mock port by C++. | 1960 "var port;\n" // Set to our mock port by C++. |
1886 "\n" | 1961 "\n" |
1887 "var x = 7;\n" | 1962 "var x = 7;\n" |
1888 "main() {\n" | 1963 "main() {\n" |
1889 " x = x * x;\n" | 1964 " 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']]"); | 1997 service_msg = Eval(h_lib, "[0, port, ['profile'], ['tags'], ['hidden']]"); |
1923 Service::HandleIsolateMessage(isolate, service_msg); | 1998 Service::HandleIsolateMessage(isolate, service_msg); |
1924 handler.HandleNextMessage(); | 1999 handler.HandleNextMessage(); |
1925 // Expect error. | 2000 // Expect error. |
1926 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | 2001 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); |
1927 } | 2002 } |
1928 | 2003 |
1929 #endif // !defined(TARGET_ARCH_ARM64) | 2004 #endif // !defined(TARGET_ARCH_ARM64) |
1930 | 2005 |
1931 } // namespace dart | 2006 } // namespace dart |
OLD | NEW |