|
| 1 | +#include "../ConcurrentHashMap.h" |
| 2 | +#include "../PersistentList.h" |
| 3 | +#include "../Hash.h" |
1 | 4 | #include "TestTools.h" |
2 | 5 | #include <math.h> |
3 | 6 |
|
4 | 7 | #define THREAD_COUNT 10 |
5 | 8 |
|
| 9 | +static bool Ptr_isShared(void *p) { |
| 10 | + return (Object_getRawRefCount((Object *)p) & SHARED_BIT) != 0; |
| 11 | +} |
| 12 | + |
6 | 13 | typedef struct HashThreadParams { |
7 | 14 | int start; |
8 | 15 | int stop; |
@@ -115,12 +122,31 @@ static void test_concurrent_hash_map_overcrowded(void **state) { |
115 | 122 | }); |
116 | 123 | } |
117 | 124 |
|
| 125 | +static void test_chm_promotion_on_assoc(void **state) { |
| 126 | + (void)state; |
| 127 | + // Initialize PersistentList_empty() singleton before the block |
| 128 | + // because otherwise it will be recorded as a "leak" (type 8) |
| 129 | + PersistentList_empty(); |
| 130 | + ASSERT_MEMORY_ALL_BALANCED({ |
| 131 | + // 1. Test shared-at-birth |
| 132 | + ConcurrentHashMap *m = ConcurrentHashMap_create(3); |
| 133 | + assert_true(Ptr_isShared(m)); |
| 134 | + |
| 135 | + // 2. Test promotion on assoc |
| 136 | + PersistentList *l = PersistentList_create(RT_boxInt32(1), PersistentList_empty()); |
| 137 | + assert_false(Ptr_isShared(l)); |
| 138 | + |
| 139 | + ConcurrentHashMap_assoc(m, RT_boxPtr(l), RT_boxInt32(100)); |
| 140 | + // The list should have been promoted because it was inserted into CHM |
| 141 | + assert_true(Ptr_isShared(l)); |
| 142 | + |
| 143 | + Ptr_release(m); |
| 144 | + }); |
| 145 | +} |
| 146 | + |
118 | 147 | int main(void) { |
119 | 148 | const struct CMUnitTest tests[] = { |
120 | | - // There are problems with the map - bad performance all around and |
121 | | - // possible |
122 | | - // race conditions. |
123 | | - // Needs to be re-implemented? or at least checked with emini |
| 149 | + cmocka_unit_test(test_chm_promotion_on_assoc), |
124 | 150 | cmocka_unit_test_prestate(testScalingBehavior, |
125 | 151 | concurrentMapThreadingAndPerformance), |
126 | 152 | cmocka_unit_test(test_concurrent_hash_map_overcrowded), |
|
0 commit comments