Example #1
0
void
testcase_run(TestCaseState_t *tcs)
{
    int no_threads, t, c;
    char *block, *p;
    Ulong zcrr_sz;

    if (!IS_SMP_ENABLED)
	testcase_skipped(tcs, "No SMP support");

    alloc = START_ALC("Zero carrier allocator", 1, NULL);

    zcrr_sz = ZERO_CRR_SIZE;

    block = p = ALLOC(alloc, zcrr_sz*TEST_NO_THREADS*TEST_NO_CARRIERS_PER_THREAD);

    ASSERT(tcs, block != NULL);    

    for (t = 0; t < TEST_NO_THREADS; t++) {
	for (c = 0; c < TEST_NO_CARRIERS_PER_THREAD; c++) {
	    Carrier_t *crr = (Carrier_t *) p;
	    p += zcrr_sz;
	    ZERO_CRR_INIT(alloc, crr);
	    threads[t].crr[c] = crr;
	}
    }

    no_threads = 0;
    for (t = 0; t < TEST_NO_THREADS; t++) {
    	threads[t].tid = THR_CREATE(thread_func, (void *) threads[t].crr);
	if (threads[t].tid) {
	    testcase_printf(tcs, "Successfully created thread %d\n", t);
	    no_threads++;
	}
	else {
	    testcase_printf(tcs, "Failed to create thread %d\n", t);
	    break;
	}
    }

    for (t = 0; t < no_threads; t++)
	THR_JOIN(threads[t].tid);

    FATAL_ASSERT(CPOOL_IS_EMPTY(alloc));

    FREE(alloc, block);

    ASSERT(tcs, no_threads == TEST_NO_THREADS);
}
Example #2
0
void
testcase_run(TestCaseState_t *tcs)
{
    struct {
	erts_thread tid;
	ThreadData arg;
    } threads[NO_OF_THREADS+1] = {{0}};
    int no_threads;
    int i;
    char sbct_buf[10];
    char *argv_org[] = {"-tasaobf", "-tmmsbc5000", "-tmmmbc5000", "-tsbct",
			&sbct_buf[0], NULL};
    char *argv[sizeof(argv_org)/sizeof(argv_org[0])];

    if (!IS_THREADS_ENABLED)
	testcase_skipped(tcs, "Threads not enabled");

    alloc_not_ts = NULL;
    alloc_ts_1 = NULL;
    alloc_ts_2 = NULL;

    err_buf[0] = '\0';

    sprintf(sbct_buf, "%d", SBC_THRESHOLD/1024);
    
    memcpy((void *) argv, argv_org, sizeof(argv_org));
    alloc_not_ts = START_ALC("threads_not_ts", 0, argv);
    ASSERT(tcs, alloc_not_ts);
    memcpy((void *) argv, argv_org, sizeof(argv_org));
    alloc_ts_1 = START_ALC("threads_ts_1", 1, argv);
    ASSERT(tcs, alloc_ts_1);
    memcpy((void *) argv, argv_org, sizeof(argv_org));
    alloc_ts_2 = START_ALC("threads_ts_2", 1, argv);
    ASSERT(tcs, alloc_ts_2);

    ASSERT(tcs, !IS_ALLOC_THREAD_SAFE(alloc_not_ts));
    ASSERT(tcs, IS_ALLOC_THREAD_SAFE(alloc_ts_1));
    ASSERT(tcs, IS_ALLOC_THREAD_SAFE(alloc_ts_2));

    tc_mutex = THR_MTX_CREATE();
    tc_cond = THR_COND_CREATE();

    THR_MTX_LOCK(tc_mutex);

    dead_thread_no = -1;
    no_threads = 0;

    for(i = 1; i <= NO_OF_THREADS; i++) {
	char *alc;

	threads[i].arg.no_ops_per_bl = NO_OF_OPS_PER_BL;

	if (i == 1) {
	    alc = "threads_not_ts";
	    threads[i].arg.no_ops_per_bl *= 2;
	    threads[i].arg.a = alloc_not_ts;
	}
	else if (i % 2 == 0) {
	    alc = "threads_ts_1";
	    threads[i].arg.a = alloc_ts_1;
	}
	else {
	    alc = "threads_ts_2";
	    threads[i].arg.a = alloc_ts_2;
	}
	threads[i].arg.t_no = i;

	threads[i].tid = THR_CREATE(thread_func, (void *) &threads[i].arg);
	if (threads[i].tid) {
	    testcase_printf(tcs, "Successfully created thread %d "
			    "using %s_alloc\n", i, alc);
	    no_threads++;
	}
	else {
	    tc_failed = 1;
	    sprintf(err_buf, "Failed to create thread %d\n", i);
	    break;
	}

    }

    while (no_threads) {
	THR_COND_WAIT(tc_cond, tc_mutex);
	if (dead_thread_no >= 0) {
	    no_threads--;
	    THR_JOIN(threads[dead_thread_no].tid);
	    testcase_printf(tcs, "Thread %d died\n", dead_thread_no);
	    dead_thread_no = -1;
	    THR_COND_BCAST(tc_cond);
	}
    }

    THR_MTX_UNLOCK(tc_mutex);
    THR_MTX_DESTROY(tc_mutex);
    THR_COND_DESTROY(tc_cond);

    stop_allocators();

    if (tc_failed)
	testcase_failed(tcs, "%s", err_buf);
}