Ignore:
Timestamp:
Feb 18, 2025, 12:54:23 PM (7 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
8705a11
Parents:
3e5fea2
Message:

Clean-up the warnings of the concurrency tests. A lot of little test level fixes, the most interesting repeated one is some formally redundent fallthough statements. pthread_attr_test had to be rewritten because of library restrictions. Changed some types so they would always be pointer sized. There was a library change, there was a function that could not be implemented; I trust that it is included for a reason so I just put it in a comment. There is a change to the compiler, wait-until now uses goto. The labelled breaks were code generated as unlabelled breaks and although it worked out slipped through some checks. Finally, there is one warning that I cannot solve at this time so tests that produce it have been put in their own lax group.

Location:
tests/concurrency/pthread
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrency/pthread/pthread_attr_test.cfa

    r3e5fea2 rd923fca  
    44#include <thread.hfa>
    55
    6 void* foo(void* _attr){
     6void* foo(void*){
     7    pthread_t self = pthread_self();
     8    pthread_attr_t self_attr;
     9    pthread_getattr_np(self, &self_attr);
     10
    711    size_t size;
    8     pthread_attr_t* attr = (pthread_attr_t*)_attr;
    9     int status = pthread_attr_getstacksize(attr, &size);
     12    int status = pthread_attr_getstacksize(&self_attr, &size);
    1013    if (status != 0){
    1114        sout | "error return code";
     
    1619}
    1720
    18 int main(int argc, char const *argv[])
     21int main()
    1922{
    2023    pthread_attr_t attr;
     
    2326    pthread_t thr;
    2427    void* res;
    25     pthread_create(&thr, &attr, foo, (void*)&attr);
     28    pthread_create(&thr, &attr, foo, (void*)0);
    2629    pthread_join(thr, &res);
    2730    pthread_attr_destroy(&attr);
  • tests/concurrency/pthread/pthread_demo_create_join.cfa

    r3e5fea2 rd923fca  
    33/* test pthread create/join/exit */
    44
    5 int arr[20];
     5size_t arr[20];
    66
    77void* fetch(void* idx){
    8     int res = arr[(uint64_t)idx];
     8    size_t res = arr[(size_t)idx];
    99    pthread_exit((void*)res);
    1010    sout | "it should not be here";
     
    1919}
    2020
    21 int main(int argc, char const *argv[])
     21int main()
    2222{
    2323    pthread_t threads[20];
    2424    arr_init();
    2525    int status;
    26     for (int i = 0; i < 20; i++){
     26    for (size_t i = 0; i < 20; i++){
    2727        status = pthread_create(&threads[i], NULL, fetch, (void*)i);
    2828        if (status != 0) exit(1);
     
    3030    int res = 0;
    3131    for (int i = 0; i < 20; i++){
    32         void* _res = NULL;
    33         status = pthread_join(threads[i], &_res);
     32        void* res_i = NULL;
     33        status = pthread_join(threads[i], &res_i);
    3434        if (status != 0) exit(2);
    35         if (((uint64_t)_res) != i) exit(3);
    36         res += (uint64_t)_res;
     35        if (((size_t)res_i) != i) exit(3);
     36        res += (size_t)res_i;
    3737    }
    3838    sout | "final res is" | res;
  • tests/concurrency/pthread/pthread_key_test.cfa

    r3e5fea2 rd923fca  
    1616    #define BUFFSZ  48
    1717    pthread_key_t   key;
    18     volatile int total_value,total_value_getspec;
     18    volatile size_t total_value;
     19    volatile size_t total_value_getspec;
    1920    pthread_mutex_t value_mutex;
    2021
     
    2627        int       *tnum;
    2728        void      *getvalue;
    28         char       Buffer[BUFFSZ];
    2929
    3030        tnum = (int*)parm;
     
    3232
    3333        //printf("Thread %d executing\n", threadnum);
    34         value = (void *)(rand()%100);
     34        value = (void *)(size_t)(rand()%100);
    3535        status = pthread_setspecific(key, (void *) value);
    3636        if ( status !=  0) {
     
    4040        }
    4141        pthread_mutex_lock(&value_mutex);
    42         total_value_getspec += (int)value;
    43         total_value += (int)pthread_getspecific(key);
     42        total_value_getspec += (size_t)value;
     43        total_value += (size_t)pthread_getspecific(key);
    4444        pthread_mutex_unlock(&value_mutex);
    4545
    4646
    47         if (!(value = malloc(sizeof(Buffer))))
     47        if (!(value = malloc(BUFFSZ)))
    4848            printf("Thread %d could not allocate storage, errno = %d\n",
    4949                                                        threadnum, errno);
     
    6060
    6161        if (getvalue != value) {
    62         printf("getvalue not valid, getvalue=%d", (u_int64_t)getvalue);
     62            printf("getvalue not valid, getvalue=%p", getvalue);
    6363            return (void*)68;
    6464        }
     
    7676
    7777    int main() {
    78         int          getvalue;
    7978        int          status;
    8079        int          i;
     
    116115
    117116            if (thread_stat[i] != 0)   {
    118                 printf("bad thread status, thread %d, status=%d\n", i+1,
    119                                                         (u_int64_t)thread_stat[i]);
     117                printf("bad thread status, thread %d, status=%zd\n", i+1,
     118                                                        (size_t)thread_stat[i]);
    120119            }
    121120        }
    122         printf("total value is %d, total value by pthread_getspecific is %d\n", total_value, total_value_getspec);
     121        printf("total value is %zd, total value by pthread_getspecific is %zd\n", total_value, total_value_getspec);
    123122        exit(0);
    124123    }   // main
Note: See TracChangeset for help on using the changeset viewer.