Works now even when compiled with optimization flags

This commit is contained in:
pithikos 2015-03-06 16:11:07 +00:00
parent 90174270f6
commit 746cf897c3
9 changed files with 62 additions and 12 deletions

View File

@ -1,11 +1,25 @@
Tests
------------------------------------------------------------------------
For memory leaks run `./memleaks`. This might take a while since valgrind
needs one second to init each thread.
**Case tests**
````
memleaks - Will run tests for memory leaks. valgrind is being used for this.
Notice that valgrind requires one second to init each thread.
threadpool - Will run general functional tests for the threadpool.
pause_resume - Will test the synchronisation of the threadpool from the user.
wait - Will run tests to assuse that the wait() function works correctly.
For the general functional tests run `./threadpool`.
````
**On errors:**
**Compilation cases**
````
normal_compile - Will run all tests above against a simply compiled threadpool.
optimized_compile - Will run all tests but against a binary that was compiled
with optimization flags.
````
**On errors**
Check the created log file `error.log`

View File

@ -37,3 +37,8 @@ function err { #string #log
echo "$2" >> error.log
exit 1
}
function compile { #cfilepath
gcc $COMPILATION_FLAGS "$1" ../thpool.c -pthread -o test
}

View File

@ -13,7 +13,7 @@
function test_thread_free { #threads
echo "Testing creation and destruction of threads(=$1)"
gcc src/no_work.c ../thpool.c -pthread -o test
compile src/no_work.c
output=$(valgrind --leak-check=full --track-origins=yes ./test "$1" 2>&1 > /dev/null)
heap_usage=$(echo "$output" | grep "total heap usage")
allocs=$(extract_num "[0-9]* allocs" "$heap_usage")
@ -32,7 +32,7 @@ function test_thread_free { #threads
# This is the same with test_many_thread_allocs but multiplied
function test_thread_free_multi { #threads #times
echo "Testing multiple threads creation and destruction in pool(threads=$1 times=$2)"
gcc src/no_work.c ../thpool.c -pthread -o test
compile src/no_work.c
for ((i = 1; i <= $2; i++)); do
python -c "import sys; sys.stdout.write('$i/$2\r')"
output=$(valgrind --leak-check=full --track-origins=yes ./test "$1" 2>&1 > /dev/null)

16
tests/normal_compile Executable file
View File

@ -0,0 +1,16 @@
#! /bin/bash
#
# This will run all tests for a simple compilation
#
# ---------------------------- Tests -----------------------------------
. threadpool
. pause_resume
. memleaks
. wait
echo "No errors"

15
tests/optimized_compile Executable file
View File

@ -0,0 +1,15 @@
#! /bin/bash
#
# This file will run all tests but with a binary that has
# been compiled with optimization flags.
#
# ---------------------------- Tests -----------------------------------
COMPILATION_FLAGS='-g -O'
. normal_compile
echo "No optimization errors"

View File

@ -13,7 +13,7 @@
function test_pause_resume_est7secs { #threads
echo "Pause and resume test for 7 secs with $1 threads"
gcc src/pause_resume.c ../thpool.c -pthread -o test
compile src/pause_resume.c
realsecs=$(/usr/bin/time -f '%e' ./test "$1" 2>&1 > /dev/null)
threshold=1.00 # in secs

View File

@ -10,7 +10,7 @@
function test_mass_addition { #endsum #threads
echo "Adding up to $1 with $2 threads"
gcc src/conc_increment.c ../thpool.c -pthread -o test
compile src/conc_increment.c
output=$(./test $1 $2)
num=$(echo $output | awk '{print $(NF)}')
if [ "$num" == "$1" ]; then

View File

@ -13,7 +13,7 @@
function test_wait_each_job { #threads #jobs
echo "Will test waiting for each job ($1 threads, $2 jobs)"
gcc src/wait.c ../thpool.c -pthread -o test
compile src/wait.c
realsecs=$(time_exec ./test $2 $1 1)
threshold=1.00 # in secs
@ -29,7 +29,7 @@ function test_wait_each_job { #threads #jobs
function test_wait_pool { #threads #jobs
echo "Will test waiting for whole threadpool ($1 threads, $2 jobs)"
gcc src/wait.c ../thpool.c -pthread -o test
compile src/wait.c
realsecs=$(time_exec ./test $2 $1 0)
threshold=1.00 # in secs

View File

@ -69,8 +69,8 @@ typedef struct thread{
/* Threadpool */
typedef struct thpool_{
thread** threads; /* pointer to threads */
int num_threads_alive; /* threads currently alive */
int num_threads_working; /* threads currently working */
volatile int num_threads_alive; /* threads currently alive */
volatile int num_threads_working; /* threads currently working */
pthread_mutex_t thcount_lock; /* used for thread count etc */
jobqueue* jobqueue_p; /* pointer to the job queue */
} thpool_;