mirror of
https://github.com/Pithikos/C-Thread-Pool
synced 2024-11-25 06:49:37 +03:00
Add unit test: run in nonzero heap/stack env.
This commit is contained in:
parent
984f6f9408
commit
5a4a92f2b3
26
tests/bugtraq.sh
Executable file
26
tests/bugtraq.sh
Executable file
@ -0,0 +1,26 @@
|
||||
#! /bin/bash
|
||||
|
||||
#
|
||||
# This file tests for possible bugs
|
||||
#
|
||||
|
||||
. funcs.sh
|
||||
|
||||
|
||||
# ---------------------------- Tests -----------------------------------
|
||||
|
||||
function test_with_nonzero_heap_and_stack {
|
||||
compile src/nonzero_heap_stack.c
|
||||
if ! timeout 1 ./test; then
|
||||
err "Fail running on nonzero heap and stack"
|
||||
exit 1
|
||||
else
|
||||
return
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# Run tests
|
||||
test_with_nonzero_heap_and_stack
|
||||
|
||||
echo "No errors"
|
56
tests/src/nonzero_heap_stack.c
Normal file
56
tests/src/nonzero_heap_stack.c
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Try to run thpool with a non-zero heap and stack
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include "../../thpool.h"
|
||||
|
||||
|
||||
void task(){
|
||||
printf("Thread #%u working on task\n", (int)pthread_self());
|
||||
}
|
||||
|
||||
|
||||
void nonzero_stack(){
|
||||
char buf[40096];
|
||||
memset(buf, 0x80, 40096);
|
||||
}
|
||||
|
||||
|
||||
void nonzero_heap(){
|
||||
|
||||
int i;
|
||||
void *ptrs[200];
|
||||
|
||||
for (i=0; i<200; i++){
|
||||
ptrs[i] = malloc((i+1) << 4);
|
||||
if (ptrs[i])
|
||||
memset(ptrs[i], 0x80, (i+1) << 4);
|
||||
}
|
||||
for (i=0; i<200; i++){
|
||||
free(ptrs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
|
||||
nonzero_stack();
|
||||
nonzero_heap();
|
||||
|
||||
puts("Making threadpool with 4 threads");
|
||||
threadpool thpool = thpool_init(4);
|
||||
|
||||
puts("Adding 20 tasks to threadpool");
|
||||
int i;
|
||||
for (i=0; i<20; i++){
|
||||
thpool_add_work(thpool, (void*)task, NULL);
|
||||
};
|
||||
|
||||
puts("Killing threadpool");
|
||||
thpool_destroy(thpool);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user