add multiple threads to mallocator test
This commit is contained in:
parent
d0f9e8dfcf
commit
2b04f8a82e
@ -1,8 +1,10 @@
|
|||||||
|
#include <aos/deferred.h>
|
||||||
#include <test_threads.h>
|
#include <test_threads.h>
|
||||||
#include <test_helper.h>
|
#include <test_helper.h>
|
||||||
#include <spawn/spawn.h>
|
#include <spawn/spawn.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#define PROCESS_COUNT 100
|
#define PROCESS_COUNT 1
|
||||||
|
|
||||||
void do_test_threads(void) {
|
void do_test_threads(void) {
|
||||||
debug_printf("[do_test_threads]\n");
|
debug_printf("[do_test_threads]\n");
|
||||||
@ -14,4 +16,19 @@ void do_test_threads(void) {
|
|||||||
debug_printf("TEST_THREADS: spawn %u\n", i);
|
debug_printf("TEST_THREADS: spawn %u\n", i);
|
||||||
CHECK_ERR(spawn_load_by_name("mallocator", &(si[i]), &(pid[i])));
|
CHECK_ERR(spawn_load_by_name("mallocator", &(si[i]), &(pid[i])));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// while (true) {
|
||||||
|
// debug_printf("[do_test_threads]: processes alive: ");
|
||||||
|
|
||||||
|
// struct spawninfo* process = spawn_get_process_list();
|
||||||
|
// while (process != NULL) {
|
||||||
|
// printf("%d, ", process->pid);
|
||||||
|
// process = process->next;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// printf("\n");
|
||||||
|
|
||||||
|
// //wait for 1 second but handle events in the mean time
|
||||||
|
// barrelfish_usleep(1000000);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,8 +19,12 @@
|
|||||||
#include <aos/paging.h>
|
#include <aos/paging.h>
|
||||||
|
|
||||||
#define NUM_SMALL_BUFFERS 128
|
#define NUM_SMALL_BUFFERS 128
|
||||||
|
#define NUM_THREADS 16
|
||||||
|
|
||||||
static void test_large_buffer(void) {
|
static struct thread* threads[NUM_THREADS];
|
||||||
|
|
||||||
|
__attribute__((__used__))
|
||||||
|
static int test_large_buffer(void * __args) {
|
||||||
//allocate a 256 MiB buffer
|
//allocate a 256 MiB buffer
|
||||||
debug_printf("allocating 256MiB buffer\n");
|
debug_printf("allocating 256MiB buffer\n");
|
||||||
char * big_buf = malloc(1<<28);
|
char * big_buf = malloc(1<<28);
|
||||||
@ -33,8 +37,12 @@ static void test_large_buffer(void) {
|
|||||||
|
|
||||||
debug_printf("freeing 256MiB buffer\n");
|
debug_printf("freeing 256MiB buffer\n");
|
||||||
free(big_buf);
|
free(big_buf);
|
||||||
|
debug_printf("thread done!\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__attribute__((__used__))
|
||||||
static void test_many_buffers(void) {
|
static void test_many_buffers(void) {
|
||||||
|
|
||||||
char* buffers[NUM_SMALL_BUFFERS];
|
char* buffers[NUM_SMALL_BUFFERS];
|
||||||
@ -52,10 +60,23 @@ static void test_many_buffers(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void test_multi_thread(void) {
|
||||||
|
for (int i = 0; i < NUM_THREADS; ++i) {
|
||||||
|
threads[i] = thread_create(test_large_buffer, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
//wait for the threads
|
||||||
|
for (int i = 0; i < NUM_THREADS; ++i) {
|
||||||
|
thread_join(threads[i], NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
test_large_buffer();
|
// test_large_buffer();
|
||||||
test_many_buffers();
|
// test_many_buffers();
|
||||||
|
test_multi_thread();
|
||||||
|
|
||||||
debug_printf("i am done!\n");
|
debug_printf("i am done!\n");
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user