Changeset 92538ab for tests


Ignore:
Timestamp:
Apr 10, 2022, 2:53:18 PM (3 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum
Children:
d8e2a09
Parents:
4559b34 (diff), 6256891 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Resolve conflict

Location:
tests
Files:
51 added
21 edited
2 moved

Legend:

Unmodified
Added
Removed
  • tests/.expect/declarationSpecifier.arm64.txt

    r4559b34 r92538ab  
    11321132char **_X13cfa_args_argvPPc_1;
    11331133char **_X13cfa_args_envpPPc_1;
    1134 signed int _X17cfa_main_returnedi_1 = ((signed int )0);
     1134__attribute__ ((weak)) extern signed int _X17cfa_main_returnedi_1;
    11351135signed int main(signed int _X4argci_1, char **_X4argvPPc_1, char **_X4envpPPc_1){
    11361136    __attribute__ ((unused)) signed int _X12_retval_maini_1;
     
    11491149    signed int _tmp_cp_ret6;
    11501150    signed int _X3reti_2 = (((void)(_tmp_cp_ret6=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret6);
    1151     {
    1152         ((void)(_X17cfa_main_returnedi_1=((signed int )1)));
     1151    if ( ((&_X17cfa_main_returnedi_1)!=((signed int *)0)) ) {
     1152        {
     1153            ((void)(_X17cfa_main_returnedi_1=((signed int )1)));
     1154        }
     1155
    11531156    }
    11541157
  • tests/.expect/gccExtensions.arm64.txt

    r4559b34 r92538ab  
    324324char **_X13cfa_args_argvPPc_1;
    325325char **_X13cfa_args_envpPPc_1;
    326 signed int _X17cfa_main_returnedi_1 = ((signed int )0);
     326__attribute__ ((weak)) extern signed int _X17cfa_main_returnedi_1;
    327327signed int main(signed int _X4argci_1, char **_X4argvPPc_1, char **_X4envpPPc_1){
    328328    __attribute__ ((unused)) signed int _X12_retval_maini_1;
     
    341341    signed int _tmp_cp_ret6;
    342342    signed int _X3reti_2 = (((void)(_tmp_cp_ret6=invoke_main(_X4argci_1, _X4argvPPc_1, _X4envpPPc_1))) , _tmp_cp_ret6);
    343     {
    344         ((void)(_X17cfa_main_returnedi_1=((signed int )1)));
     343    if ( ((&_X17cfa_main_returnedi_1)!=((signed int *)0)) ) {
     344        {
     345            ((void)(_X17cfa_main_returnedi_1=((signed int )1)));
     346        }
     347
    345348    }
    346349
  • tests/.expect/random.arm64.txt

    r4559b34 r92538ab  
    11õ
    22=
    3 V
     3K
    44-911259971
    556
    6 -4
     611
    771232105397
    880
    9 18
     911
    1010-914096085
    11111
    12 15
     1220
    13132077092859
    14141
    15 11
     1512
    16160.677254
    17170.678106775246139
  • tests/Makefile.am

    r4559b34 r92538ab  
    2828DEBUG_FLAGS=-debug -g -O0
    2929
    30 quick_test=avl_test operators numericConstants expression enum array typeof cast raii/dtor-early-exit raii/init_once attributes
     30quick_test=avl_test operators numericConstants expression enum array typeof cast raii/dtor-early-exit raii/init_once attributes meta/dumpable
    3131
    3232concurrent=
     
    6666PRETTY_PATH=mkdir -p $(dir $(abspath ${@})) && cd ${srcdir} &&
    6767
    68 .PHONY: list .validate
    69 .INTERMEDIATE: .validate .validate.cfa
     68.PHONY: list .validate .test_makeflags
     69.INTERMEDIATE: .validate .validate.cfa .test_makeflags
    7070EXTRA_PROGRAMS = avl_test linkonce .dummy_hack # build but do not install
    7171EXTRA_DIST = test.py \
     
    123123        @+${TEST_PY} --list ${concurrent}
    124124
     125.test_makeflags:
     126        @echo "${MAKEFLAGS}"
     127
    125128.validate: .validate.cfa
    126129        $(CFACOMPILE) .validate.cfa -fsyntax-only -Wall -Wextra -Werror
  • tests/PRNG.cfa

    r4559b34 r92538ab  
    88// Created On       : Wed Dec 29 09:38:12 2021
    99// Last Modified By : Peter A. Buhr
    10 // Last Modified On : Fri Feb 11 08:16:43 2022
    11 // Update Count     : 328
     10// Last Modified On : Sat Apr  9 15:21:14 2022
     11// Update Count     : 344
    1212//
    1313
     
    2020#include <malloc.h>                                                                             // malloc_stats
    2121#include <locale.h>                                                                             // setlocale
    22 
    23 // FIX ME: spurious characters appear in output
    24 Duration default_preemption() { return 0; }
     22#include <mutex_stmt.hfa>
    2523
    2624#ifdef TIME                                                                                             // use -O2 -nodebug
     
    5048        } // for
    5149        double std = sqrt( sum / BUCKETS );
    52         sout | "trials"  | TRIALS | "buckets" | BUCKETS
    53                  | "min" | min | "max" | max
    54                  | "avg" | wd(0,1, avg) | "std" | wd(0,1, std) | "rstd" | wd(0,1, (avg == 0 ? 0.0 : std / avg * 100)) | "%";
     50        mutex( sout ) sout | "trials"  | TRIALS | "buckets" | BUCKETS
     51                | "min" | min | "max" | max
     52                | "avg" | wd(0,1, avg) | "std" | wd(0,1, std) | "rstd" | wd(0,1, (avg == 0 ? 0.0 : std / avg * 100)) | "%";
    5553} // avgstd
    5654
     55
    5756uint32_t seed = 1009;
    58 
    5957
    6058thread T1 {};
     
    9492        unsigned int * buckets = calloc( BUCKETS );                     // too big for task stack
    9593        for ( TRIALS ) {
    96                 buckets[prng( (thread$ &)th ) % BUCKETS] += 1;  // concurrent
     94                buckets[prng( th ) % BUCKETS] += 1;     // concurrent
    9795        } // for
    9896        avgstd( buckets );
  • tests/collections/.expect/string-api-coverage.txt

    r4559b34 r92538ab  
    11hello hello hello
     2
     3hello
    24true false
    35true false
  • tests/collections/.expect/string-gc.txt

    r4559b34 r92538ab  
    3838x from 5 to 15
    3939y from 5 to 15
     40======================== fillNoCompact
     41about to expand, a = aaa
     42expanded, a = aaa
     43about to expand, a = aaa
     44expanded, a = aaa
     45about to expand, a = aaa
     46expanded, a = aaa
     47about to expand, a = aaa
     48expanded, a = aaa
     49about to expand, a = aaa
     50expanded, a = aaa
  • tests/collections/.expect/vector-err-pass-perm-it-byval.txt

    r4559b34 r92538ab  
    1 error: Unique best alternative includes deleted identifier in Generated Cast of:
     1collections/vector-demo.cfa:95:1 error: Unique best alternative includes deleted identifier in Generated Cast of:
    22  Application of
    33    Deleted Expression
  • tests/collections/string-api-coverage.cfa

    r4559b34 r92538ab  
    11#include <containers/string.hfa>
     2#include <string_sharectx.hfa>
    23
    34void assertWellFormedHandleList( int maxLen ) { // with(HeapArea)
     
    2526
    2627int main () {
     28
     29    #ifdef STRING_SHARING_OFF
     30    string_sharectx c = { NO_SHARING };
     31    #endif
     32
    2733    string s = "hello";
    2834    string s2 = "hello";
     
    3137
    3238    // IO operator, x2
    33     sout | s | s | s;
     39    sout | s | s | s;  // hello hello hello
     40
     41    // empty ctor then assign
     42    string sxx;
     43    sout | sxx;  // (blank line)
     44    sxx = s;
     45    sout | sxx;  // hello
    3446
    3547    // Comparisons
  • tests/collections/string-gc.cfa

    r4559b34 r92538ab  
    22
    33size_t bytesRemaining() {
    4     return DEBUG_string_bytes_avail_until_gc( DEBUG_string_heap );
     4    return DEBUG_string_bytes_avail_until_gc( DEBUG_string_heap() );
    55}
    66
    77size_t heapOffsetStart( string_res & s ) {
    8     const char * startByte = DEBUG_string_heap_start( DEBUG_string_heap );
     8    const char * startByte = DEBUG_string_heap_start( DEBUG_string_heap() );
    99    assert( s.Handle.s >= startByte );
    1010    return s.Handle.s - startByte;
     
    120120}
    121121
     122void fillNoCompact() {
     123    // show that allocating in a heap filled with mostly live strings (no collectable garbage) causes heap growth
     124
     125    sout | "======================== fillNoCompact";
     126
     127    size_t lastTimeBytesAvail = bytesRemaining();
     128    assert( lastTimeBytesAvail >= 200 ); // starting this test with nontrivial room
     129
     130    // mostly fill the pad
     131    string_res a = "aaa";  // will have to be moved
     132    string_res z = "zzz";
     133    for (i; 5) {
     134        while ( bytesRemaining() > 10 ) {
     135            z += ".";
     136        }
     137        sout | "about to expand, a = " | a;
     138        while ( bytesRemaining() <= 10 ) {
     139            z += ".";
     140        }
     141        sout | "expanded, a = " | a;
     142
     143        // each growth gives more usable space than the last
     144        assert( bytesRemaining() > lastTimeBytesAvail );
     145        lastTimeBytesAvail = bytesRemaining();
     146    }
     147}
     148
    122149int main() {
    123150    basicFillCompact();
    124151    fillCompact_withSharedEdits();
     152    fillNoCompact();
    125153}
  • tests/collections/string-overwrite.cfa

    r4559b34 r92538ab  
    11#include <containers/string.hfa>
     2#include <string_sharectx.hfa>
    23
    34/*
     
    1112WE = witness end
    1213
    13 The dest does:
     14The test does:
    1415  starts with the entire string being, initially, the alphabet; prints this entire alphabet
    1516  sets up modifier and witness as ranges within it, and prints a visualization of those ranges
     
    2425This API's convention has Start positions being inclusive and end positions being exclusive.
    2526
     27                                v Case number in output
    2628With 1 equivalence class:
    2729MS = ME = WS = WE               1
     
    118120    struct { int ms; int me; int ws; int we; char *replaceWith; char *label; } cases[] = {
    119121        { 12, 14, 10, 20, "xxxxx", "warmup" },
    120 //        { 12, 14, 12, 14, "xxxxx", ""       },  // the bug that got me into this test (should be a dup with case 6)
    121122        { 10, 10, 10, 10, "=====", "1"      },
    122123        { 10, 10, 10, 10, "=="   , ""       },
     
    223224        { 12, 14, 10, 16, "="    , ""       },
    224225        { 12, 14, 10, 16, ""     , ""       },
    225 /*
    226         { , , , , "=====", "NN"     },
    227         {  "=="   , ""       },
    228         {  "="    , ""       },
    229         {  ""     , ""       },
    230 */
    231226    };
    232227    for ( i; sizeof(cases)/sizeof(cases[0]) ) {
     
    238233
    239234
    240 // void f( string & s, string & toEdit ) {
    241 
    242 //     sout | s | "|" | toEdit | "|";
    243 
    244 //     s(14, 16) = "-";
    245 //     sout | s | "|" | toEdit | "|";
    246 // }
    247 
    248235int main() {
     236
     237    #ifdef STRING_SHARING_OFF
     238    string_sharectx c = { NO_SHARING };
     239    #endif
     240
     241
    249242    //          0         1         2
    250243    //          01234567890123456789012345
  • tests/concurrent/mutexstmt/.expect/locks.txt

    r4559b34 r92538ab  
    33Start Test: multi lock deadlock/mutual exclusion
    44End Test: multi lock deadlock/mutual exclusion
    5 Start Test: single scoped lock mutual exclusion
    6 End Test: single scoped lock mutual exclusion
    7 Start Test: multi scoped lock deadlock/mutual exclusion
    8 End Test: multi scoped lock deadlock/mutual exclusion
     5Start Test: multi polymorphic lock deadlock/mutual exclusion
     6End Test: multi polymorphic lock deadlock/mutual exclusion
  • tests/concurrent/mutexstmt/locks.cfa

    r4559b34 r92538ab  
    33
    44const unsigned int num_times = 10000;
     5
     6Duration default_preemption() { return 0; }
    57
    68single_acquisition_lock m1, m2, m3, m4, m5;
     
    2224}
    2325
     26void refTest( single_acquisition_lock & m ) {
     27        mutex ( m ) {
     28                assert(!insideFlag);
     29                insideFlag = true;
     30                assert(insideFlag);
     31                insideFlag = false;
     32        }
     33}
     34
    2435thread T_Multi {};
    2536
    2637void main( T_Multi & this ) {
    2738        for (unsigned int i = 0; i < num_times; i++) {
     39                refTest( m1 );
    2840                mutex ( m1 ) {
    2941                        assert(!insideFlag);
     
    5971}
    6072
    61 thread T_Mutex_Scoped {};
     73single_acquisition_lock l1;
     74linear_backoff_then_block_lock l2;
     75owner_lock l3;
    6276
    63 void main( T_Mutex_Scoped & this ) {
     77monitor monitor_t {};
     78
     79monitor_t l4;
     80
     81thread T_Multi_Poly {};
     82
     83void main( T_Multi_Poly & this ) {
    6484        for (unsigned int i = 0; i < num_times; i++) {
    65                 {
    66                         scoped_lock(single_acquisition_lock) s{m1};
    67                         count++;
    68                 }
    69                 {
    70                         scoped_lock(single_acquisition_lock) s{m1};
     85                refTest( l1 );
     86                mutex ( l1, l4 ) {
    7187                        assert(!insideFlag);
    7288                        insideFlag = true;
     
    7490                        insideFlag = false;
    7591                }
    76         }
    77 }
    78 
    79 thread T_Multi_Scoped {};
    80 
    81 void main( T_Multi_Scoped & this ) {
    82         for (unsigned int i = 0; i < num_times; i++) {
    83                 {
    84                         scoped_lock(single_acquisition_lock) s{m1};
     92                mutex ( l1, l2, l3 ) {
    8593                        assert(!insideFlag);
    8694                        insideFlag = true;
     
    8896                        insideFlag = false;
    8997                }
    90                 {
    91                         scoped_lock(single_acquisition_lock) s1{m1};
    92                         scoped_lock(single_acquisition_lock) s2{m2};
    93                         scoped_lock(single_acquisition_lock) s3{m3};
    94                         scoped_lock(single_acquisition_lock) s4{m4};
    95                         scoped_lock(single_acquisition_lock) s5{m5};
     98                mutex ( l3, l1, l4 ) {
    9699                        assert(!insideFlag);
    97100                        insideFlag = true;
     
    99102                        insideFlag = false;
    100103                }
    101                 {
    102                         scoped_lock(single_acquisition_lock) s1{m1};
    103                         scoped_lock(single_acquisition_lock) s3{m3};
    104                         assert(!insideFlag);
    105                         insideFlag = true;
    106                         assert(insideFlag);
    107                         insideFlag = false;
    108                 }
    109                 {
    110                         scoped_lock(single_acquisition_lock) s1{m1};
    111                         scoped_lock(single_acquisition_lock) s2{m2};
    112                         scoped_lock(single_acquisition_lock) s4{m4};
    113                         assert(!insideFlag);
    114                         insideFlag = true;
    115                         assert(insideFlag);
    116                         insideFlag = false;
    117                 }
    118                 {
    119                         scoped_lock(single_acquisition_lock) s1{m1};
    120                         scoped_lock(single_acquisition_lock) s3{m3};
    121                         scoped_lock(single_acquisition_lock) s4{m4};
    122                         scoped_lock(single_acquisition_lock) s5{m5};
     104                mutex ( l1, l2, l4 ) {
    123105                        assert(!insideFlag);
    124106                        insideFlag = true;
     
    131113int num_tasks = 10;
    132114int main() {
    133         processor p[10];
     115        processor p[num_tasks - 1];
    134116
    135117        printf("Start Test: single lock mutual exclusion\n");
    136118        {
    137                 T_Mutex t[10];
     119                T_Mutex t[num_tasks];
    138120        }
    139121        assert(count == num_tasks * num_times);
     
    141123        printf("Start Test: multi lock deadlock/mutual exclusion\n");
    142124        {
    143                 T_Multi t[10];
     125                T_Multi t[num_tasks];
    144126        }
    145127        printf("End Test: multi lock deadlock/mutual exclusion\n");
    146        
    147         count = 0;
    148         printf("Start Test: single scoped lock mutual exclusion\n");
     128        printf("Start Test: multi polymorphic lock deadlock/mutual exclusion\n");
    149129        {
    150                 T_Mutex_Scoped t[10];
     130                T_Multi_Poly t[num_tasks];
    151131        }
    152         assert(count == num_tasks * num_times);
    153         printf("End Test: single scoped lock mutual exclusion\n");
    154         printf("Start Test: multi scoped lock deadlock/mutual exclusion\n");
    155         {
    156                 T_Multi_Scoped t[10];
    157         }
    158         printf("End Test: multi scoped lock deadlock/mutual exclusion\n");     
     132        printf("End Test: multi polymorphic lock deadlock/mutual exclusion\n");
    159133}
  • tests/designations.cfa

    r4559b34 r92538ab  
    1010// Created On       : Thu Jun 29 15:26:36 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 27 11:46:35 2017
    13 // Update Count     : 3
     12// Last Modified On : Mon Mar 28 22:41:55 2022
     13// Update Count     : 15
    1414//
    1515
     
    1818// is used for the designation syntax
    1919#ifdef __cforall
    20 #define DES :
     20#define _ :
     21#define AT @
    2122#else
    22 int printf(const char *, ...);
    23 #define DES =
     23int printf( const char *, ...);
     24#define _ =
     25#define AT
    2426#endif
    2527
    2628const int indentAmt = 2;
    27 void indent(int level) {
    28         for (int i = 0; i < level; ++i) {
    29                 printf(" ");
     29void indent( int level ) {
     30        for ( int i = 0; i < level; ++i ) {
     31                printf( " " );
    3032        }
    3133}
     
    3638        int * ptr;
    3739};
    38 void printA(struct A a, int level) {
    39         indent(level);
    40         printf("(A){ %d %d %p }\n", a.x, a.y, a.ptr);
     40void printA( struct A a, int level ) {
     41        indent( level );
     42        printf( "(A){ %d %d %p }\n", a.x, a.y, a.ptr );
    4143}
    4244
     
    4547        struct A a0, a1;
    4648};
    47 void printB(struct B b, int level) {
    48         indent(level);
    49         printf("(B){\n");
    50         printA(b.a0, level+indentAmt);
    51         printA(b.a1, level+indentAmt);
    52         indent(level);
    53         printf("}\n");
     49void printB( struct B b, int level ) {
     50        indent( level );
     51        printf( "(B){\n" );
     52        printA( b.a0, level+indentAmt );
     53        printA( b.a1, level+indentAmt );
     54        indent( level );
     55        printf( "}\n" );
    5456}
    5557
     
    5961        struct B b;
    6062};
    61 void printC(struct C c, int level) {
    62         indent(level);
    63         printf("(C){\n");
    64         indent(level+indentAmt);
    65         printf("(int[]{ %d %d %d }\n", c.arr[0], c.arr[1], c.arr[2]);
    66         printB(c.b, level+indentAmt);
    67         indent(level);
    68         printf("}\n");
     63void printC( struct C c, int level ) {
     64        indent( level );
     65        printf( "(C){\n" );
     66        indent( level+indentAmt );
     67        printf( "(int[]{ %d %d %d }\n", c.arr[0], c.arr[1], c.arr[2]);
     68        printB( c.b, level+indentAmt );
     69        indent( level );
     70        printf( "}\n" );
    6971}
    7072
     
    7577        };
    7678};
    77 void printD(struct D d, int level) {
    78         indent(level);
    79         printf("(D){ %d }\n", d.x);
     79void printD( struct D d, int level ) {
     80        indent( level);
     81        printf( "(D ){ %d }\n", d.x );
    8082}
    8183
     
    99101    } m;
    100102};
    101 struct Fred s1 @= { .m.j : 3 };
    102 struct Fred s2 @= { .i : { [2] : 2 } };
     103struct Fred s1 AT= { .m.j _ 3 };
     104struct Fred s2 AT= { .i _ { [2] _ 2 } };
    103105
    104106int main() {
    105107        // simple designation case - starting from beginning of structure, leaves ptr default-initialized (zero)
    106108        struct A y0 = {
    107                 .x DES 2,
    108                 .y DES 3
     109                .x _ 2,
     110                .y _ 3
    109111        };
    110112
     
    117119        // use designation to move to member y, leaving x default-initialized (zero)
    118120        struct A y2 = {
    119                 .y DES 3,
     121                .y _ 3,
    120122                0
    121123        };
     
    127129#endif
    128130
    129         printf("=====A=====\n");
    130         printA(y0, 0);
    131         printA(y1, 0);
    132         printA(y2, 0);
    133         printf("=====A=====\n\n");
     131        printf( "=====A=====\n" );
     132        printA( y0, 0 );
     133        printA( y1, 0 );
     134        printA( y2, 0 );
     135        printf( "=====A=====\n\n" );
    134136
    135137        // initialize only first element (z0.a.x), leaving everything else default-initialized (zero), no nested curly-braces
     
    140142                { 3 }, // z1.a0
    141143                { 4 }, // z1.a1
    142                 .a0 DES { 5 }, // z1.a0
     144                .a0 _ { 5 }, // z1.a0
    143145                { 6 }, // z1.a1
    144                 .a0.y DES 2, // z1.a0.y
     146                .a0.y _ 2, // z1.a0.y
    145147                0, // z1.a0.ptr
    146148        };
     
    170172        };
    171173
    172         printf("=====B=====\n");
    173         printB(z0, 0);
    174         printB(z1, 0);
    175         printB(z2, 0);
    176         printB(z3, 0);
    177         printB(z5, 0);
    178         printB(z6, 0);
    179         printf("=====B=====\n\n");
     174        printf( "=====B=====\n" );
     175        printB( z0, 0 );
     176        printB( z1, 0 );
     177        printB( z2, 0 );
     178        printB( z3, 0 );
     179        printB( z5, 0 );
     180        printB( z6, 0 );
     181        printf( "=====B=====\n\n" );
    180182
    181183        // TODO: what about extra things in a nested init? are empty structs skipped??
     
    188190        };
    189191
    190         printf("=====C=====\n");
    191         printC(c1, 0);
    192         printf("=====C=====\n\n");
     192        printf( "=====C=====\n" );
     193        printC( c1, 0 );
     194        printf( "=====C=====\n\n" );
    193195
    194196#if ERROR
     
    213215#endif
    214216        // array designation
    215         int i[2] = { [1] : 3 };
     217        int i[2] = { [1] _ 3 };
    216218        // allowed to have 'too many' initialized lists - essentially they are ignored.
    217219        int i1 = { 3 };
     
    219221        // doesn't work yet.
    220222        // designate unnamed object's members
    221         // struct D d = { .x DES 3 };
     223        // struct D d = { .x _ 3 };
    222224#if ERROR
    223         struct D d1 = { .y DES 3 };
     225        struct D d1 = { .y _ 3 };
    224226#endif
    225227
     
    241243        // move cursor to e4.b.a0.x and initialize until e3.b.a1.ptr inclusive
    242244        union E e3 = {
    243                 .b.a0.x DES 2, 3, 0, 5, 6, 0
    244         };
    245 
    246         printf("=====E=====\n");
    247         printA(e0.a, 0);
    248         printA(e1.a, 0);
    249         printA(e2.a, 0);
    250         printB(e3.b, 0);
    251         printf("=====E=====\n\n");
     245                .b.a0.x _ 2, 3, 0, 5, 6, 0
     246        };
     247
     248        printf( "=====E=====\n" );
     249        printA( e0.a, 0 );
     250        printA( e1.a, 0 );
     251        printA( e2.a, 0 );
     252        printB( e3.b, 0 );
     253        printf( "=====E=====\n\n" );
    252254
    253255        // special case of initialization: char[] can be initialized with a string literal
    254256        const char * str0 = "hello";
    255257        char str1[] = "hello";
    256         const char c1[] = "abc";
    257         const char c2[] = { 'a', 'b', 'c' };
    258         const char c3[][2] = { { 'a', 'b' }, { 'c', 'd'}, { 'c', 'd'} };
     258        const char c2[] = "abc";
     259        const char c3[] = { 'a', 'b', 'c' };
     260        const char c4[][2] = { { 'a', 'b' }, { 'c', 'd'}, { 'c', 'd'} };
     261
     262        // more cases
     263
     264//      int widths[] = { [3 ... 9] _ 1, [10 ... 99] _ 2, [100] _ 3 };
     265//      int widths[] = { [3 ~ 9] _ 1, [10 ~ 99] _ 2, [100] _ 3 };
     266        struct point { int x, y; };
     267        struct point p = { .y _ 5, .x _ 7 };
     268        union foo { int i; double d; };
     269        union foo f = { .d _ 4 };
     270        int v1, v2, v4;
     271        int w[6] = { [1] _ v1, v2, [4] _ v4 };
     272        int whitespace[256] = { [' '] _ 1, ['\t'] _ 1, ['\v'] _ 1, ['\f'] _ 1, ['\n'] _ 1, ['\r'] _ 1 };
     273        struct point ptarray[10] = { [2].y _ 34, [2].x _ 35, [0].x _ 36 };
    259274}
    260275
  • tests/errors/.expect/scope.txt

    r4559b34 r92538ab  
    44  double
    55... returning
    6   _retval_butThisIsAnError: double
    7   ... with attributes:
    8     Attribute with name: unused
     6  double
     7 with body
     8  Compound Statement:
    99
    10 ... with body
    11   CompoundStmt
    12 
  • tests/io/io-acquire.cfa

    r4559b34 r92538ab  
    1010// Created On       : Mon Mar  1 18:40:09 2021
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jan 14 09:13:18 2022
    13 // Update Count     : 74
     12// Last Modified On : Sat Apr  9 15:22:03 2022
     13// Update Count     : 76
    1414//
    1515
     
    1717#include <thread.hfa>
    1818#include <mutex_stmt.hfa>
    19 
    20 Duration default_preemption() { return 0; }
    2119
    2220thread T {};
  • tests/io/many_read.cfa

    r4559b34 r92538ab  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // many_read.cfa -- Make sure that multiple concurrent reads to mess up.
     7// many_read.cfa -- Make sure that multiple concurrent reads don't mess up.
    88//
    99// Author           : Thierry Delisle
  • tests/meta/dumpable.cfa

    r4559b34 r92538ab  
    1414//
    1515
     16#include <errno.h>
    1617#include <limits.h>
    17 #include <errno.h>
     18#include <string.h>
    1819
    1920#include <fstream.hfa>
    2021
    2122extern "C" {
     23        #include <fcntl.h>
     24        #include <unistd.h>
    2225        #include <sys/prctl.h>
    2326        #include <sys/resource.h>
    2427        #include <sys/statvfs.h>
    25         #include <unistd.h>
     28        #include <sys/stat.h>
     29        #include <sys/types.h>
    2630}
    2731
     
    7276        }
    7377
    74         if((buf.f_bsize * buf.f_bavail) < 536870912) {
    75                 serr | "Available diskspace is less than ~500Mb: " | (buf.f_bsize * buf.f_bavail);
     78        uint64_t avail = buf.f_bavail;
     79        avail *= buf.f_bsize;
     80        if(avail < 536870912_l64u) {
     81                serr | "Available diskspace is less than ~500Mb: " | avail;
    7682        }
    7783
     
    100106}
    101107
     108void check_core_pattern() {
     109        int ret;
     110        int cp = open("/proc/sys/kernel/core_pattern", 0, O_RDONLY);
     111        if(cp < 0) {
     112                perror("open(/proc/sys/kernel/core_pattern, O_RDONLY) error");
     113                return;
     114        }
     115
     116        try {
     117                const char * expected = "core\n";
     118                const int sz = sizeof("core\n");
     119                char buf[512];
     120                ret = read(cp, buf, 512);
     121                if(ret < 0) {
     122                        perror("first core pattern read error");
     123                        return;
     124                }
     125                ret = strncmp(expected, buf, sz - 1);
     126                if(ret != 0) {
     127                        serr | "/proc/sys/kernel/core_pattern does not contain 'core', was:" | nl | nl | buf | nl
     128                             | "Test script expect cores files to be dumped with name 'core' in current working directory." | nl
     129                             | "Apport is not supported, it should be deactivated in /etc/default/apport for the test suite to work with core dumps.";
     130
     131                        return;
     132                }
     133        }
     134        finally {
     135                ret = close(cp);
     136                if(ret < 0) perror("close(/proc/sys/kernel/core_pattern) error");
     137        }
     138
     139}
     140
    102141int main() {
    103142        check_ulimit();
     
    111150        check_dumpflag();
    112151
     152        check_core_pattern();
     153
    113154        sout | "Done";
    114155}
  • tests/pybin/settings.py

    r4559b34 r92538ab  
    155155        global generating
    156156        global make
     157        global make_jobfds
    157158        global output_width
    158159        global timeout
     
    168169        generating   = options.regenerate_expected
    169170        make         = ['make']
     171        make_jobfds  = []
    170172        output_width = 24
    171173        timeout      = Timeouts(options.timeout, options.global_timeout)
     
    177179                os.putenv('DISTCC_LOG', os.path.join(BUILDDIR, 'distcc_error.log'))
    178180
    179 def update_make_cmd(force, jobs):
     181def update_make_cmd(flags):
    180182        global make
    181 
    182         make = ['make'] if not force else ['make', "-j%i" % jobs]
     183        make = ['make', *flags]
     184
     185def update_make_fds(r, w):
     186        global make_jobfds
     187        make_jobfds = (r, w)
    183188
    184189def validate():
     
    187192        global distcc
    188193        distcc       = "DISTCC_CFA_PATH=~/.cfadistcc/%s/cfa" % tools.config_hash()
    189         errf = os.path.join(BUILDDIR, ".validate.err")
    190         make_ret, out = tools.make( ".validate", error_file = errf, output_file=subprocess.DEVNULL, error=subprocess.DEVNULL )
     194        make_ret, out, err = tools.make( ".validate", output_file=subprocess.PIPE, error=subprocess.PIPE )
    191195        if make_ret != 0:
    192                 with open (errf, "r") as myfile:
    193                         error=myfile.read()
    194196                print("ERROR: Invalid configuration %s:%s" % (arch.string, debug.string), file=sys.stderr)
    195                 print("       verify returned : \n%s" % error, file=sys.stderr)
    196                 tools.rm(errf)
     197                print("       verify returned : \n%s" % err, file=sys.stderr)
    197198                sys.exit(1)
    198 
    199         tools.rm(errf)
    200199
    201200def prep_output(tests):
  • tests/pybin/tools.py

    r4559b34 r92538ab  
    2323
    2424# helper functions to run terminal commands
    25 def sh(*cmd, timeout = False, output_file = None, input_file = None, input_text = None, error = subprocess.STDOUT, ignore_dry_run = False):
     25def sh(*cmd, timeout = False, output_file = None, input_file = None, input_text = None, error = subprocess.STDOUT, ignore_dry_run = False, pass_fds = []):
    2626        try:
    2727                cmd = list(cmd)
     
    6565                                **({'input' : bytes(input_text, encoding='utf-8')} if input_text else {'stdin' : input_file}),
    6666                                stdout  = output_file,
    67                                 stderr  = error
     67                                stderr  = error,
     68                                pass_fds = pass_fds
    6869                        ) as proc:
    6970
    7071                                try:
    71                                         out, _ = proc.communicate(
     72                                        out, errout = proc.communicate(
    7273                                                timeout = settings.timeout.single if timeout else None
    7374                                        )
    7475
    75                                         return proc.returncode, out.decode("latin-1") if out else None
     76                                        return proc.returncode, out.decode("latin-1") if out else None, errout.decode("latin-1") if errout else None
    7677                                except subprocess.TimeoutExpired:
    7778                                        if settings.timeout2gdb:
    7879                                                print("Process {} timeout".format(proc.pid))
    7980                                                proc.communicate()
    80                                                 return 124, str(None)
     81                                                return 124, str(None), "Subprocess Timeout 2 gdb"
    8182                                        else:
    8283                                                proc.send_signal(signal.SIGABRT)
    8384                                                proc.communicate()
    84                                                 return 124, str(None)
     85                                                return 124, str(None), "Subprocess Timeout 2 gdb"
    8586
    8687        except Exception as ex:
     
    105106                return (False, "No file")
    106107
    107         code, out = sh("file", fname, output_file=subprocess.PIPE)
     108        code, out, err = sh("file", fname, output_file=subprocess.PIPE)
    108109        if code != 0:
    109                 return (False, "'file EXPECT' failed with code {}".format(code))
     110                return (False, "'file EXPECT' failed with code {} '{}'".format(code, err))
    110111
    111112        match = re.search(".*: (.*)", out)
     
    190191        ]
    191192        cmd = [s for s in cmd if s]
    192         return sh(*cmd, output_file=output_file, error=error)
     193        return sh(*cmd, output_file=output_file, error=error, pass_fds=settings.make_jobfds)
    193194
    194195def make_recon(target):
     
    241242# move a file
    242243def mv(source, dest):
    243         ret, _ = sh("mv", source, dest)
     244        ret, _, _ = sh("mv", source, dest)
    244245        return ret
    245246
    246247# cat one file into the other
    247248def cat(source, dest):
    248         ret, _ = sh("cat", source, output_file=dest)
     249        ret, _, _ = sh("cat", source, output_file=dest)
    249250        return ret
    250251
     
    289290#               system
    290291################################################################################
     292def jobserver_version():
     293        make_ret, out, err = sh('make', '.test_makeflags', '-j2', output_file=subprocess.PIPE, error=subprocess.PIPE)
     294        if make_ret != 0:
     295                print("ERROR: cannot find Makefile jobserver version", file=sys.stderr)
     296                print("       test returned : {} '{}'".format(make_ret, err), file=sys.stderr)
     297                sys.exit(1)
     298
     299        re_jobs = re.search("--jobserver-(auth|fds)", out)
     300        if not re_jobs:
     301                print("ERROR: cannot find Makefile jobserver version", file=sys.stderr)
     302                print("       MAKEFLAGS are : '{}'".format(out), file=sys.stderr)
     303                sys.exit(1)
     304
     305        return "--jobserver-{}".format(re_jobs.group(1))
     306
     307def prep_recursive_make(N):
     308        if N < 2:
     309                return []
     310
     311        # create the pipe
     312        (r, w) = os.pipe()
     313
     314        # feel it with N-1 tokens, (Why N-1 and not N, I don't know it's in the manpage for make)
     315        os.write(w, b'+' * (N - 1));
     316
     317        # prep the flags for make
     318        make_flags = ["-j{}".format(N), "--jobserver-auth={},{}".format(r, w)]
     319
     320        # tell make about the pipes
     321        os.environ["MAKEFLAGS"] = os.environ["MFLAGS"] = " ".join(make_flags)
     322
     323        # make sure pass the pipes to our children
     324        settings.update_make_fds(r, w)
     325
     326        return make_flags
     327
     328def prep_unlimited_recursive_make():
     329        # prep the flags for make
     330        make_flags = ["-j"]
     331
     332        # tell make about the pipes
     333        os.environ["MAKEFLAGS"] = os.environ["MFLAGS"] = "-j"
     334
     335        return make_flags
     336
     337
     338def eval_hardware():
     339        # we can create as many things as we want
     340        # how much hardware do we have?
     341        if settings.distribute:
     342                # remote hardware is allowed
     343                # how much do we have?
     344                ret, jstr, _ = sh("distcc", "-j", output_file=subprocess.PIPE, ignore_dry_run=True)
     345                return int(jstr.strip()) if ret == 0 else multiprocessing.cpu_count()
     346        else:
     347                # remote isn't allowed, use local cpus
     348                return multiprocessing.cpu_count()
     349
    291350# count number of jobs to create
    292 def job_count( options, tests ):
     351def job_count( options ):
    293352        # check if the user already passed in a number of jobs for multi-threading
    294         if not options.jobs:
    295                 make_flags = os.environ.get('MAKEFLAGS')
    296                 force = bool(make_flags)
    297                 make_jobs_fds = re.search("--jobserver-(auth|fds)=\s*([0-9]+),([0-9]+)", make_flags) if make_flags else None
    298                 if make_jobs_fds :
    299                         tokens = os.read(int(make_jobs_fds.group(2)), 1024)
    300                         options.jobs = len(tokens)
    301                         os.write(int(make_jobs_fds.group(3)), tokens)
    302                 else :
    303                         if settings.distribute:
    304                                 ret, jstr = sh("distcc", "-j", output_file=subprocess.PIPE, ignore_dry_run=True)
    305                                 if ret == 0:
    306                                         options.jobs = int(jstr.strip())
    307                                 else :
    308                                         options.jobs = multiprocessing.cpu_count()
    309                         else:
    310                                 options.jobs = multiprocessing.cpu_count()
     353        make_env = os.environ.get('MAKEFLAGS')
     354        make_flags = make_env.split() if make_env else None
     355        jobstr = jobserver_version()
     356
     357        if options.jobs and make_flags:
     358                print('WARNING: -j options should not be specified when called form Make', file=sys.stderr)
     359
     360        # Top level make is calling the shots, just follow
     361        if make_flags:
     362                # do we have -j and --jobserver-...
     363                jobopt = None
     364                exists_fds = None
     365                for f in make_flags:
     366                        jobopt = f if f.startswith("-j") else jobopt
     367                        exists_fds = f if f.startswith(jobstr) else exists_fds
     368
     369                # do we have limited parallelism?
     370                if exists_fds :
     371                        try:
     372                                rfd, wfd = tuple(exists_fds.split('=')[1].split(','))
     373                        except:
     374                                print("ERROR: jobserver has unrecoginzable format, was '{}'".format(exists_fds), file=sys.stderr)
     375                                sys.exit(1)
     376
     377                        # read the token pipe to count number of available tokens and restore the pipe
     378                        # this assumes the test suite script isn't invoked in parellel with something else
     379                        tokens = os.read(int(rfd), 65536)
     380                        os.write(int(wfd), tokens)
     381
     382                        # the number of tokens is off by one for obscure but well documented reason
     383                        # see man make for more details
     384                        options.jobs = len(tokens) + 1
     385
     386                # do we have unlimited parallelism?
     387                elif jobopt and jobopt != "-j1":
     388                        # check that this actually make sense
     389                        if jobopt != "-j":
     390                                print("ERROR: -j option passed by make but no {}, was '{}'".format(jobstr, jobopt), file=sys.stderr)
     391                                sys.exit(1)
     392
     393                        options.jobs = eval_hardware()
     394                        flags = prep_unlimited_recursive_make()
     395
     396
     397                # then no parallelism
     398                else:
     399                        options.jobs = 1
     400
     401                # keep all flags make passed along, except the weird 'w' which is about subdirectories
     402                flags = [f for f in make_flags if f != 'w']
     403
     404        # Arguments are calling the shots, fake the top level make
     405        elif options.jobs :
     406
     407                # make sure we have a valid number of jobs that corresponds to user input
     408                if options.jobs < 0 :
     409                        print('ERROR: Invalid number of jobs', file=sys.stderr)
     410                        sys.exit(1)
     411
     412                flags = prep_recursive_make(options.jobs)
     413
     414        # Arguments are calling the shots, fake the top level make, but 0 is a special case
     415        elif options.jobs == 0:
     416                options.jobs = eval_hardware()
     417                flags = prep_unlimited_recursive_make()
     418
     419        # No one says to run in parallel, then don't
    311420        else :
    312                 force = True
    313 
    314         # make sure we have a valid number of jobs that corresponds to user input
    315         if options.jobs <= 0 :
    316                 print('ERROR: Invalid number of jobs', file=sys.stderr)
    317                 sys.exit(1)
    318 
    319         return min( options.jobs, len(tests) ), force
     421                options.jobs = 1
     422                flags = []
     423
     424        # Make sure we call make as expected
     425        settings.update_make_cmd( flags )
     426
     427        # return the job count
     428        return options.jobs
    320429
    321430# enable core dumps for all the test children
     
    334443        distcc_hash = os.path.join(settings.SRCDIR, '../tools/build/distcc_hash')
    335444        config = "%s-%s" % (settings.arch.target, settings.debug.path)
    336         _, out = sh(distcc_hash, config, output_file=subprocess.PIPE, ignore_dry_run=True)
     445        _, out, _ = sh(distcc_hash, config, output_file=subprocess.PIPE, ignore_dry_run=True)
    337446        return out.strip()
    338447
     
    374483
    375484        if not os.path.isfile(core):
    376                 return 1, "ERR No core dump (limit soft: {} hard: {})".format(*resource.getrlimit(resource.RLIMIT_CORE))
     485                return 1, "ERR No core dump, expected '{}' (limit soft: {} hard: {})".format(core, *resource.getrlimit(resource.RLIMIT_CORE))
    377486
    378487        try:
    379                 return sh('gdb', '-n', path, core, '-batch', '-x', cmd, output_file=subprocess.PIPE)
     488                ret, out, err = sh('gdb', '-n', path, core, '-batch', '-x', cmd, output_file=subprocess.PIPE)
     489                if ret == 0:
     490                        return 0, out
     491                else:
     492                        return 1, err
    380493        except:
    381494                return 1, "ERR Could not read core with gdb"
  • tests/test.py

    r4559b34 r92538ab  
    140140        parser.add_argument('--regenerate-expected', help='Regenerate the .expect by running the specified tets, can be used with --all option', action='store_true')
    141141        parser.add_argument('--archive-errors', help='If called with a valid path, on test crashes the test script will copy the core dump and the executable to the specified path.', type=str, default='')
    142         parser.add_argument('-j', '--jobs', help='Number of tests to run simultaneously', type=int)
     142        parser.add_argument('-j', '--jobs', help='Number of tests to run simultaneously, 0 (default) for unlimited', nargs='?', const=0, type=int)
    143143        parser.add_argument('--list-comp', help='List all valide arguments', action='store_true')
    144144        parser.add_argument('--list-dist', help='List all tests for distribution', action='store_true')
     
    195195        # build, skipping to next test on error
    196196        with Timed() as comp_dur:
    197                 make_ret, _ = make( test.target(), output_file=subprocess.DEVNULL, error=out_file, error_file = err_file )
     197                make_ret, _, _ = make( test.target(), output_file=subprocess.DEVNULL, error=out_file, error_file = err_file )
    198198
    199199        # ----------
     
    208208                                if settings.dry_run or is_exe(exe_file):
    209209                                        # run test
    210                                         retcode, _ = sh(exe_file, output_file=out_file, input_file=in_file, timeout=True)
     210                                        retcode, _, _ = sh(exe_file, output_file=out_file, input_file=in_file, timeout=True)
    211211                                else :
    212212                                        # simply cat the result into the output
     
    226226                        else :
    227227                                # fetch return code and error from the diff command
    228                                 retcode, error = diff(cmp_file, out_file)
     228                                retcode, error, _ = diff(cmp_file, out_file)
    229229
    230230                else:
     
    366366                        print(os.path.relpath(t.expect(), settings.SRCDIR), end=' ')
    367367                        print(os.path.relpath(t.input() , settings.SRCDIR), end=' ')
    368                         code, out = make_recon(t.target())
     368                        code, out, err = make_recon(t.target())
    369369
    370370                        if code != 0:
    371                                 print('ERROR: recond failed for test {}'.format(t.target()), file=sys.stderr)
     371                                print('ERROR: recond failed for test {}: {} \'{}\''.format(t.target(), code, err), file=sys.stderr)
    372372                                sys.exit(1)
    373373
     
    417417                        if is_empty(t.expect()):
    418418                                print('WARNING: test "{}" has empty .expect file'.format(t.target()), file=sys.stderr)
     419
     420        options.jobs = job_count( options )
    419421
    420422        # for each build configurations, run the test
     
    430432                        local_tests = settings.ast.filter( tests )
    431433                        local_tests = settings.arch.filter( local_tests )
    432                         options.jobs, forceJobs = job_count( options, local_tests )
    433                         settings.update_make_cmd(forceJobs, options.jobs)
    434434
    435435                        # check the build configuration works
    436436                        settings.validate()
     437                        jobs = min(options.jobs, len(local_tests))
    437438
    438439                        # print configuration
     
    440441                                'Regenerating' if settings.generating else 'Running',
    441442                                len(local_tests),
    442                                 options.jobs,
     443                                jobs,
    443444                                settings.ast.string,
    444445                                settings.arch.string,
     
    450451
    451452                        # otherwise run all tests and make sure to return the correct error code
    452                         failed = run_tests(local_tests, options.jobs)
     453                        failed = run_tests(local_tests, jobs)
    453454                        if failed:
    454455                                if not settings.continue_:
Note: See TracChangeset for help on using the changeset viewer.