Added test number 10 (needs x86 library though)

This commit is contained in:
rajdakin 2019-06-23 14:33:54 +02:00
parent 34ae8d5274
commit 83d1b68ef5
4 changed files with 45 additions and 0 deletions

View File

@ -11,6 +11,7 @@ option(NOALIGN "Set to ON if host device doesn't need re-align (i.e. i386)" ${NO
option(HAVE_TRACE "Set to ON to have Trace ability (needs ZydisInfo library)" ${HAVE_TRACE})
option(USE_FLOAT "Set to ON to use only float, no double, in all x87 Emulation" ${USE_FLOAT})
option(NOLOADADDR "Set to ON to avoid fixing the load address of Box86" ${NO_LOADAADR})
option(X86_CPP_LIBRARY_PRESENT "Set to ON if you have an accessible libstdc++.so.6 32bit ELF lib in your PATH" ${X86_CPP_LIBRARY_PRESENT})
# Pandora
if(PANDORA)
@ -181,3 +182,10 @@ add_test(test09 ${CMAKE_COMMAND} -D TEST_PROGRAM=${CMAKE_BINARY_DIR}/${BOX86}
-D TEST_ARGS=${CMAKE_SOURCE_DIR}/tests/test09 -D TEST_OUTPUT=tmpfile.txt
-D TEST_REFERENCE=${CMAKE_SOURCE_DIR}/tests/ref09.txt
-P ${CMAKE_SOURCE_DIR}/runTest.cmake )
if(X86_CPP_LIBRARY_PRESENT)
add_test(test10 ${CMAKE_COMMAND} -D TEST_PROGRAM=${CMAKE_BINARY_DIR}/${BOX86}
-D TEST_ARGS=${CMAKE_SOURCE_DIR}/tests/test10 -D TEST_OUTPUT=tmpfile.txt
-D TEST_REFERENCE=${CMAKE_SOURCE_DIR}/tests/ref10.txt
-P ${CMAKE_SOURCE_DIR}/runTest.cmake )
endif(X86_CPP_LIBRARY_PRESENT)

10
tests/ref10.txt Normal file
View File

@ -0,0 +1,10 @@
thread #0
thread #1
thread #2
thread #3
thread #4
thread #5
thread #6
thread #7
thread #8
thread #9

BIN
tests/test10 Executable file

Binary file not shown.

27
tests/test10.cpp Normal file
View File

@ -0,0 +1,27 @@
// using atomic as a lock
#include <iostream> // std::cout
#include <atomic> // std::atomic
#include <thread> // std::thread
#include <vector> // std::vector
#include <sstream> // std::stringstream
std::atomic<bool> lock_stream[10];
std::stringstream stream;
void append_number(int x) {
while (lock_stream[x].load()) {}
stream << "thread #" << x << '\n';
if (x != 9) lock_stream[x + 1].store(false);
}
int main ()
{
std::vector<std::thread> threads;
for (int i = 0; i < 10; ++i) lock_stream[i].store(true);
for (int i=0; i<10; ++i) threads.push_back(std::thread(append_number,i));
lock_stream[0].store(false);
for (auto& th : threads) th.join();
std::cout << stream.str();
return 0;
}