Changeset 18d7aaf for tests


Ignore:
Timestamp:
Jul 19, 2024, 6:06:34 PM (7 hours ago)
Author:
JiadaL <j82liang@…>
Branches:
master
Children:
9c2ac95
Parents:
d68a3f7 (diff), ce0b8b8 (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:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
tests
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tests/meta/dumpable.cfa

    rd68a3f7 r18d7aaf  
    99// Author           : Thierry Delisle
    1010// Created On       : Wed Jan 05 13:53:22 2022
    11 // Last Modified By :
    12 // Last Modified On :
    13 // Update Count     :
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Jul 19 07:58:45 2024
     13// Update Count     : 10
    1414//
    1515
     
    1717#include <limits.h>
    1818#include <string.h>
     19#include <unistd.h>
    1920
    2021#include <fstream.hfa>
     
    2223extern "C" {
    2324        #include <fcntl.h>
    24         #include <unistd.h>
    2525        #include <sys/prctl.h>
    2626        #include <sys/resource.h>
     
    3232void check_ulimit() {
    3333        struct rlimit rlp;
    34         getrlimit(RLIMIT_CORE, &rlp);
    35         if(rlp.rlim_cur < 536870912) {
     34        getrlimit( RLIMIT_CORE, &rlp );
     35        if ( rlp.rlim_cur < 536870912 ) {
    3636                serr | "Soft core limit is less than ~500Mb: " | rlp.rlim_cur;
    37         }
     37        } // if
    3838
    39         if(rlp.rlim_max < 536870912) {
     39        if ( rlp.rlim_max < 536870912 ) {
    4040                serr | "Hard core limit is less than ~500Mb: " | rlp.rlim_max;
    41         }
     41        } // if
    4242}
    4343
    4444void check_permission() {
    45         {
    46                 char myExe[PATH_MAX];
    47                 ssize_t n = readlink("/proc/self/exe", myExe, sizeof(myExe));
    48                 if (n < 0) {
    49                         perror("readlink(/proc/self/exe) error");
    50                         return 1;
    51                 }
    52                 myExe[n] = '\0';
     45        char myExe[PATH_MAX];
     46        ssize_t n = readlink( "/proc/self/exe", myExe, sizeof(myExe));
     47        if ( n < 0 ) {
     48                perror( "readlink(/proc/self/exe ) error" );
     49                return 1;
     50        } // if
     51        myExe[n] = '\0';
    5352
    54                 if(int r = access(myExe, F_OK); r != 0) serr | "Expected current executable does not exist!" | r | errno;
    55                 if(int r = access(myExe, R_OK); r != 0) serr | "No read access for current executable" | r | errno;
    56         }
     53        if ( int r = access( myExe, F_OK ); r != 0 ) serr | "Expected current executable does not exist!" | r | errno;
     54        if ( int r = access( myExe, R_OK ); r != 0 ) serr | "No read access for current executable" | r | errno;
    5755
    58         {
    59                 char myCwd[PATH_MAX];
    60                 if (getcwd(myCwd, sizeof(myCwd)) == 0p) {
    61                         perror("getcwd() error");
    62                         return;
    63                 }
     56        char myCwd[PATH_MAX];
     57        if ( getcwd( myCwd, sizeof(myCwd ) ) == 0p ) {
     58                perror( "getcwd() error" );
     59                return;
     60        } // if
    6461
    65                 if(access(myCwd, F_OK) != 0) serr | "Expected current working directory does not exist!";
    66                 if(access(myCwd, R_OK) != 0) serr | "No read access for current working directory";
    67                 if(access(myCwd, W_OK) != 0) serr | "No write access for current working directory";
    68         }
     62        if ( access( myCwd, F_OK ) != 0 ) serr | "Expected current working directory does not exist!";
     63        if ( access( myCwd, R_OK ) != 0 ) serr | "No read access for current working directory";
     64        if ( access( myCwd, W_OK ) != 0 ) serr | "No write access for current working directory";
    6965}
    7066
    7167void check_free_space() {
    7268        struct statvfs buf;
    73         if(statvfs(".", &buf) != 0) {
    74                 perror("statvfs() error");
     69        if ( statvfs( ".", &buf ) != 0 ) {
     70                perror( "statvfs() error" );
    7571                return;
    76         }
     72        } // if
    7773
    7874        uint64_t avail = buf.f_bavail;
    7975        avail *= buf.f_bsize;
    80         if(avail < 536870912_l64u) {
     76        if ( avail < 536870912_l64u ) {
    8177                serr | "Available diskspace is less than ~500Mb: " | avail;
    82         }
     78        } // if
    8379
    84         if(buf.f_favail < 10) {
     80        if ( buf.f_favail < 10 ) {
    8581                serr | "Available inodes is less than 10: " | buf.f_favail;
    86         }
     82        } // if
    8783
    88         if(buf.f_flag & ST_RDONLY) {
     84        if ( buf.f_flag & ST_RDONLY ) {
    8985                serr | "Filesystem is read only";
    90         }
     86        } // if
    9187}
    9288
    9389void check_noconflict() {
    94         char * name = "./core";
    95         if(access("./core", F_OK) == 0) serr | "A file of the core name ('" | name | "') already exists";
     90        const char * name = "./core";
     91        if ( access( name, F_OK ) == 0 ) serr | "File \"" | name | "\" already exists";
    9692}
    9793
    9894void check_dumpflag() {
    99         int r = prctl(PR_GET_DUMPABLE, 0, 0, 0, 0);
    100         if(r < 0) {
    101                 perror("prctl(PR_GET_DUMPABLE) error");
     95        int r = prctl( PR_GET_DUMPABLE, 0, 0, 0, 0 );
     96        if ( r < 0 ) {
     97                perror( "prctl( PR_GET_DUMPABLE ) error" );
    10298                return;
    103         }
     99        } // if
    104100
    105         if(r != 1) serr | "dumpable attribute not set to 1 \"(SUID_DUMP_USER, process is dumpable)\", was" | r;
     101        if ( r != 1 ) serr | "dumpable attribute not set to 1 \"( SUID_DUMP_USER, process is dumpable )\", was" | r;
    106102}
    107103
    108104void check_core_pattern() {
    109105        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");
     106        int cp = open( "/proc/sys/kernel/core_pattern", 0, O_RDONLY );
     107
     108        if ( cp < 0 ) {
     109                perror( "open(/proc/sys/kernel/core_pattern, O_RDONLY ) error" );
    113110                return;
    114         }
     111        } // if
    115112
    116113        try {
    117114                const char * expected = "core\n";
    118                 const int sz = sizeof("core\n");
     115                const int sz = sizeof( "core\n" );
    119116                char buf[512];
    120                 ret = read(cp, buf, 512);
    121                 if(ret < 0) {
    122                         perror("first core pattern read error");
     117                ret = read( cp, buf, 512 );
     118                if ( ret < 0 ) {
     119                        perror( "core pattern read error" );
    123120                        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.";
     121                } // if
    130122
    131                         return;
    132                 }
    133         }
    134         finally {
    135                 ret = close(cp);
    136                 if(ret < 0) perror("close(/proc/sys/kernel/core_pattern) error");
    137         }
    138 
     123                ret = strncmp( expected, buf, sz - 1 );
     124                if ( ret != 0 ) {
     125                        serr | "Apport is supported on your system, which means the test-suite core-dump feature does not work." | nl
     126                                 | "This is not a test failure, just a limitation on debugging output should a test fail.";
     127                } // if
     128        } finally {
     129                ret = close( cp );
     130                if ( ret < 0 ) perror( "close( /proc/sys/kernel/core_pattern ) error" );
     131        } // try
    139132}
    140133
    141134int main() {
    142135        check_ulimit();
    143 
    144136        check_permission();
    145 
    146137        check_free_space();
    147 
    148138        check_noconflict();
    149 
    150139        check_dumpflag();
    151 
    152140        check_core_pattern();
    153 
    154141        sout | "Done";
    155142}
  • tests/time.cfa

    rd68a3f7 r18d7aaf  
    1010// Created On       : Tue Mar 27 17:24:56 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 18 21:56:01 2024
    13 // Update Count     : 64
     12// Last Modified On : Fri Jul 19 08:06:59 2024
     13// Update Count     : 75
    1414//
    1515
     
    1818#include <stdlib.h>                                                                             // putenv
    1919
    20 extern "C" size_t malloc_unfreed() { return 337; }              // unfreed storage from tzset
     20extern "C" size_t malloc_unfreed() { return 1024; }             // guess at unfreed storage from putenv
    2121
    2222int main() {
    2323        // Set fixed time location to obtain repeatable output where ever run.
    24         putenv("TZ=America/Toronto");                                           // set fixed time zone
     24        putenv( "TZ=America/Toronto" );                                         // set fixed time zone
     25        // tzset has the stupidest interface I have ever seen.
    2526        tzset();                                                                                        // set time zone
    2627
     
    8182    sout | buf;
    8283} // main
    83 
    84 // Local Variables: //
    85 // mode: c //
    86 // tab-width: 4 //
    87 // compile-command: "cfa time.cfa" //
    88 // End: //
Note: See TracChangeset for help on using the changeset viewer.