Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
pbo-linaro committed Oct 16, 2024
1 parent 2c60cb7 commit 957d0fe
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
44 changes: 44 additions & 0 deletions mt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <atomic>
#include <iostream>
#include <thread>
#include <vector>

static std::atomic<uint64_t> count;
static std::atomic<int> threads_launched;

static void run(int num_threads, int num_iterations)
{
threads_launched++;
while (threads_launched != num_threads) {
/* active wait */
}

uint64_t res = 0;
for (int i = 0; i < num_iterations; ++i) {
res += 1;
}
count += res;
}

int main(int argc, char *argv[])
{
if (argc != 3) {
std::cout << "usage: num_threads num_iterations\n";
exit(EXIT_FAILURE);
}

const int num_threads = std::stoi(argv[1]);
const int num_iterations = std::stoi(argv[2]);
std::vector<std::thread> threads;

for (int i = 0; i < num_threads; ++i) {
threads.push_back(std::thread(run, num_threads, num_iterations));
}
for (auto & t : threads) {
t.join();
}
assert(count == num_iterations * num_threads);
}
34 changes: 34 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

set -eu

./build.sh

ARCH=${ARCH:-amd64}
qemu_system_args=
if [ "$ARCH" == amd64 ]; then
qemu_suffix=x86_64
elif [ "$ARCH" == i386 ]; then
qemu_suffix=i386
elif [ "$ARCH" == arm64v8 ]; then
qemu_suffix=aarch64
qemu_system_args="-M virt"
fi

gui_run=$(which xvfb-run || true)

g++ mt.cpp -o build/mt

qemu_user=./build/qemu-$qemu_suffix
qemu_system="./build/qemu-system-$qemu_suffix $qemu_system_args"
bin="build/mt 17 1000" # 17 threads, 1000 iterations
$qemu_user -plugin build/tests/tcg/plugins/libinline.so -d plugin "$@" $bin
#$qemu_user -plugin build/tests/tcg/plugins/libinline.so "$@" \
# -d op,op_opt,in_asm,out_asm $bin |& head -n 1000 > build/plugin.on
#$qemu_user "$@" -d op,op_opt,in_asm,out_asm $bin |&
# head -n 1000 > build/plugin.off
echo -----------------------------------------
#$gui_run timeout --preserve-status 2 $qemu_system\
# -plugin build/tests/plugin/libinline.so -smp 8
#vim build/plugin_sys
#vimdiff build/plugin.*

0 comments on commit 957d0fe

Please sign in to comment.