SkipListSet has UB somewhere...

This commit is contained in:
2023-10-21 19:24:33 +02:00
parent 5c6ca432ab
commit 99656b0e65
4 changed files with 21 additions and 13 deletions

View File

@@ -117,12 +117,16 @@ void stress() {
char buf[69];
itoa(curi, buf, 10);
all_tty_putstr("stress ");
all_tty_putstr(buf);
all_tty_putstr("\n");
remove_self();
}
void templates_tester() {
all_tty_putstr("Testing templates\n");
test_templates();
for (int i = 0; i < 200000; i++)
test_templates();
all_tty_putstr("Testing templates OK\n");
remove_self();
@@ -144,6 +148,8 @@ void ktask_main() {
new_ktask(mtest2, "mtest2");
new_ktask(mtest3, "mtest3");
new_ktask(templates_tester, "templates_tester");
new_ktask(templates_tester, "templates_tester2");
new_ktask(templates_tester, "templates_tester3");
new_ktask(stress_tester, "stress_tester");
remove_self();

View File

@@ -1,5 +1,5 @@
target_include_directories(kernel.elf PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_sources(kernel.elf PRIVATE mutex.cpp cv.cpp cppsupport.cpp Spinlock.cpp LockGuard.cpp rand.c)
target_sources(kernel.elf PRIVATE mutex.cpp cv.cpp cppsupport.cpp Spinlock.cpp LockGuard.cpp rand.cpp)
add_subdirectory(templates)

View File

@@ -2,18 +2,20 @@
// Created by Stepan Usatiuk on 21.10.2023.
//
#include <atomic>
#include "rand.h"
// The following functions define a portable implementation of rand and srand.
static unsigned long int next = 1;// NB: "unsigned long int" is assumed to be 32 bits wide
static std::atomic<unsigned long int> next = 1;// NB: "unsigned long int" is assumed to be 32 bits wide
int rand(void)// RAND_MAX assumed to be 32767
extern "C" int rand(void)// RAND_MAX assumed to be 32767
{
next = next * 1103515245 + 12345;
return (unsigned int) (next / 65536ULL) % 32768;
}
void srand(unsigned int seed) {
extern "C" void srand(unsigned int seed) {
next = seed;
}

View File

@@ -35,7 +35,7 @@ public:
assert(test2->size() == 2);
assert((*test2)[1] == "Thingy2");
all_tty_putstr("SharedPtr tests ok!\n");
// all_tty_putstr("SharedPtr tests ok!\n");
return true;
}
};
@@ -79,7 +79,7 @@ public:
assert(test12.ptr.get() != test1.ptr.get());
assert(test22.ptr.get() != test2.ptr.get());
all_tty_putstr("COWPointer tests ok!\n");
// all_tty_putstr("COWPointer tests ok!\n");
return true;
}
};
@@ -119,7 +119,7 @@ public:
assert(testv1[2] == "H6");
assert(testv2[2] == "H5");
all_tty_putstr("Vector tests ok!\n");
// all_tty_putstr("Vector tests ok!\n");
return true;
}
};
@@ -139,7 +139,7 @@ public:
str2 = "abcd";
assert(str1 <= str2);
all_tty_putstr("String tests ok!\n");
// all_tty_putstr("String tests ok!\n");
return true;
}
};
@@ -169,7 +169,7 @@ public:
test1.add(78, "test78", true);
assert(test1.find(78)->data == "test78");
all_tty_putstr("SkipList tests ok!\n");
// all_tty_putstr("SkipList tests ok!\n");
return true;
}
};
@@ -199,7 +199,7 @@ public:
test1.add(78, true);
assert(test1.find(78)->key == 78);
all_tty_putstr("SkipListSet tests ok!\n");
// all_tty_putstr("SkipListSet tests ok!\n");
return true;
}
};
@@ -208,8 +208,8 @@ int test_templates() {
SkipListTester SLTester;
SLTester.test();
SkipListSetTester SLSTester;
SLSTester.test();
// SkipListSetTester SLSTester;
// SLSTester.test();
StringTester stringTester;
stringTester.test();
VectorTester vectorTester;