| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 "bin/builtin.h" | 5 #include "bin/builtin.h" |
| 6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
| 7 #include "include/dart_debugger_api.h" | 7 #include "include/dart_debugger_api.h" |
| 8 #include "include/dart_mirrors_api.h" | 8 #include "include/dart_mirrors_api.h" |
| 9 #include "include/dart_native_api.h" | 9 #include "include/dart_native_api.h" |
| 10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
| (...skipping 2866 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2877 static void EpilogueCallbackTimes4() { | 2877 static void EpilogueCallbackTimes4() { |
| 2878 global_epilogue_callback_status *= 4; | 2878 global_epilogue_callback_status *= 4; |
| 2879 } | 2879 } |
| 2880 | 2880 |
| 2881 | 2881 |
| 2882 static void EpilogueCallbackTimes5() { | 2882 static void EpilogueCallbackTimes5() { |
| 2883 global_epilogue_callback_status *= 5; | 2883 global_epilogue_callback_status *= 5; |
| 2884 } | 2884 } |
| 2885 | 2885 |
| 2886 | 2886 |
| 2887 TEST_CASE(AddGarbageCollectionCallbacks) { | |
| 2888 // Prologue callback addition testing. | |
| 2889 | |
| 2890 // Add a prologue callback. | |
| 2891 EXPECT_VALID(Dart_AddGcPrologueCallback(&PrologueCallbackTimes2)); | |
| 2892 | |
| 2893 // Add the same prologue callback again. This is an error. | |
| 2894 EXPECT(Dart_IsError(Dart_AddGcPrologueCallback(&PrologueCallbackTimes2))); | |
| 2895 | |
| 2896 // Add another prologue callback. This is an error. | |
| 2897 EXPECT(Dart_IsError(Dart_AddGcPrologueCallback(&PrologueCallbackTimes3))); | |
| 2898 | |
| 2899 // Epilogue callback addition testing. | |
| 2900 | |
| 2901 // Add an epilogue callback. | |
| 2902 EXPECT_VALID(Dart_AddGcEpilogueCallback(&EpilogueCallbackTimes4)); | |
| 2903 | |
| 2904 // Add the same epilogue callback again. This is an error. | |
| 2905 EXPECT(Dart_IsError(Dart_AddGcEpilogueCallback(&EpilogueCallbackTimes4))); | |
| 2906 | |
| 2907 // Add annother epilogue callback. This is an error. | |
| 2908 EXPECT(Dart_IsError(Dart_AddGcEpilogueCallback(&EpilogueCallbackTimes5))); | |
| 2909 } | |
| 2910 | |
| 2911 | |
| 2912 TEST_CASE(RemoveGarbageCollectionCallbacks) { | |
| 2913 // Prologue callback removal testing. | |
| 2914 | |
| 2915 // Remove a prologue callback that has not been added. This is an error. | |
| 2916 EXPECT(Dart_IsError(Dart_RemoveGcPrologueCallback(&PrologueCallbackTimes2))); | |
| 2917 | |
| 2918 // Add a prologue callback. | |
| 2919 EXPECT_VALID(Dart_AddGcPrologueCallback(&PrologueCallbackTimes2)); | |
| 2920 | |
| 2921 // Remove a prologue callback. | |
| 2922 EXPECT_VALID(Dart_RemoveGcPrologueCallback(&PrologueCallbackTimes2)); | |
| 2923 | |
| 2924 // Remove a prologue callback again. This is an error. | |
| 2925 EXPECT(Dart_IsError(Dart_RemoveGcPrologueCallback(&PrologueCallbackTimes2))); | |
| 2926 | |
| 2927 // Add a prologue callback. | |
| 2928 EXPECT_VALID(Dart_AddGcPrologueCallback(&PrologueCallbackTimes2)); | |
| 2929 | |
| 2930 // Remove a prolog callback that was not added. This is an error. | |
| 2931 EXPECT(Dart_IsError(Dart_RemoveGcPrologueCallback(&PrologueCallbackTimes3))); | |
| 2932 | |
| 2933 // Epilogue callback removal testing. | |
| 2934 | |
| 2935 // Remove epilogue callback that was not added. This is an error. | |
| 2936 EXPECT(Dart_IsError(Dart_RemoveGcEpilogueCallback(&EpilogueCallbackTimes4))); | |
| 2937 | |
| 2938 // Add an epilogue callback. | |
| 2939 EXPECT_VALID(Dart_AddGcEpilogueCallback(&EpilogueCallbackTimes4)); | |
| 2940 | |
| 2941 // Remove an epilogue callback. | |
| 2942 EXPECT_VALID(Dart_RemoveGcEpilogueCallback(&EpilogueCallbackTimes4)); | |
| 2943 | |
| 2944 // Remove an epilogue callback again. This is an error. | |
| 2945 EXPECT(Dart_IsError(Dart_RemoveGcEpilogueCallback(&EpilogueCallbackTimes4))); | |
| 2946 | |
| 2947 // Add an epilogue callbacks. | |
| 2948 EXPECT_VALID(Dart_AddGcEpilogueCallback(&EpilogueCallbackTimes4)); | |
| 2949 | |
| 2950 // Remove an epilogue callback that was not added. This is an error. | |
| 2951 EXPECT(Dart_IsError(Dart_RemoveGcEpilogueCallback(&EpilogueCallbackTimes5))); | |
| 2952 } | |
| 2953 | |
| 2954 | |
| 2955 TEST_CASE(SetGarbageCollectionCallbacks) { | 2887 TEST_CASE(SetGarbageCollectionCallbacks) { |
| 2956 // GC callback addition testing. | 2888 // GC callback addition testing. |
| 2957 | 2889 |
| 2958 // Add GC callbacks. | 2890 // Add GC callbacks. |
| 2959 EXPECT_VALID(Dart_SetGcCallbacks(&PrologueCallbackTimes2, | 2891 EXPECT_VALID(Dart_SetGcCallbacks(&PrologueCallbackTimes2, |
| 2960 &EpilogueCallbackTimes4)); | 2892 &EpilogueCallbackTimes4)); |
| 2961 | 2893 |
| 2962 // Add the same callbacks again. This is an error. | 2894 // Add the same callbacks again. This is an error. |
| 2963 EXPECT(Dart_IsError(Dart_SetGcCallbacks(&PrologueCallbackTimes2, | 2895 EXPECT(Dart_IsError(Dart_SetGcCallbacks(&PrologueCallbackTimes2, |
| 2964 &EpilogueCallbackTimes4))); | 2896 &EpilogueCallbackTimes4))); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3062 EXPECT_EQ(6, global_prologue_callback_status); | 2994 EXPECT_EQ(6, global_prologue_callback_status); |
| 3063 EXPECT_EQ(28, global_epilogue_callback_status); | 2995 EXPECT_EQ(28, global_epilogue_callback_status); |
| 3064 | 2996 |
| 3065 // Garbage collect old space again. Callbacks are persistent so the | 2997 // Garbage collect old space again. Callbacks are persistent so the |
| 3066 // prologue and epilogue status values should change again. | 2998 // prologue and epilogue status values should change again. |
| 3067 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 2999 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 3068 EXPECT_EQ(12, global_prologue_callback_status); | 3000 EXPECT_EQ(12, global_prologue_callback_status); |
| 3069 EXPECT_EQ(112, global_epilogue_callback_status); | 3001 EXPECT_EQ(112, global_epilogue_callback_status); |
| 3070 | 3002 |
| 3071 // Remove the prologue and epilogue callbacks | 3003 // Remove the prologue and epilogue callbacks |
| 3072 EXPECT_VALID(Dart_RemoveGcPrologueCallback(&PrologueCallbackTimes2)); | 3004 EXPECT_VALID(Dart_SetGcCallbacks(NULL, NULL)); |
| 3073 EXPECT_VALID(Dart_RemoveGcEpilogueCallback(&EpilogueCallbackTimes4)); | |
| 3074 | 3005 |
| 3075 // Garbage collect old space. No callbacks should be invoked. No | 3006 // Garbage collect old space. No callbacks should be invoked. No |
| 3076 // status values should change. | 3007 // status values should change. |
| 3077 global_prologue_callback_status = 3; | 3008 global_prologue_callback_status = 3; |
| 3078 global_epilogue_callback_status = 7; | 3009 global_epilogue_callback_status = 7; |
| 3079 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); | 3010 Isolate::Current()->heap()->CollectGarbage(Heap::kOld); |
| 3080 EXPECT_EQ(3, global_prologue_callback_status); | 3011 EXPECT_EQ(3, global_prologue_callback_status); |
| 3081 EXPECT_EQ(7, global_epilogue_callback_status); | 3012 EXPECT_EQ(7, global_epilogue_callback_status); |
| 3082 } | 3013 } |
| 3083 | 3014 |
| (...skipping 4996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8080 NewString("main"), | 8011 NewString("main"), |
| 8081 1, | 8012 1, |
| 8082 dart_args); | 8013 dart_args); |
| 8083 int64_t value = 0; | 8014 int64_t value = 0; |
| 8084 result = Dart_IntegerToInt64(result, &value); | 8015 result = Dart_IntegerToInt64(result, &value); |
| 8085 EXPECT_VALID(result); | 8016 EXPECT_VALID(result); |
| 8086 EXPECT_EQ(6, value); | 8017 EXPECT_EQ(6, value); |
| 8087 } | 8018 } |
| 8088 | 8019 |
| 8089 } // namespace dart | 8020 } // namespace dart |
| OLD | NEW |