void fprint_token(FILE *ofile, const Token tk) { /* Prints a regular token in two characters: normal char meta (bit 9 set) ^A cntl $A meta-cntl A printable #A meta and hashed tokens in hexadecimal. */ int tki = Token2int(tk); int ch = tki & 0x7F; int bit8 = tki & 0x80; if (Token_EQ(tk, No_Token)) {fprintf(ofile, "--"); return;} if (Token_EQ(tk, IDF)) {fprintf(ofile, "IDF"); return;} if (Token_EQ(tk, End_Of_Line)) {fprintf(ofile, "EOL"); return;} if (is_simple_token(tk)) { if ('!' <= ch && ch <= '~') { fprintf(ofile, "%s%c", (bit8 ? "8" : ""), ch); return; } if (0 < ch && ch <= ' ') { fprintf(ofile, "%s%c", (bit8 ? "$" : "^"), ch + '@'); return; } if (ch == 0x7F) { fprintf(ofile, "%s%c", (bit8 ? "$" : "^"), '?'); return; } } if (is_CTRL_token(tk)) { if (check_and_print(ofile, "CTRL", ch, 'A', '~', '@')) return; } if (is_NORM_token(tk)) { if (check_and_print(ofile, "NORM", ch, '!', '~', '\0')) return; } if (is_MTCT_token(tk)) { if (check_and_print(ofile, "MTCT", ch, 'A', '~', '@')) return; } if (is_META_token(tk)) { if (check_and_print(ofile, "META", ch, '!', '~', '\0')) return; } if (is_hashed_token(tk)) { fprintf(ofile, "0x%04x", tki); return; } /* gap token! */ fprintf(ofile, "!0x%04x!", tki); }
static void test_eloop(void) { TEST(rename(elooppathname, TEST_NEW_ELOOP)); check_and_print(ELOOP); if (TEST_RETURN == 0) SAFE_UNLINK(cleanup, TEST_NEW_ELOOP); }
static void test_emlink(void) { if (max_subdirs == 0) { tst_resm(TCONF, "EMLINK test is not appropriate"); return; } TEST(rename(TEST_EMLINK, TEST_NEW_EMLINK)); check_and_print(EMLINK); if (TEST_RETURN == 0) SAFE_RMDIR(cleanup, TEST_NEW_EMLINK); }
static void test_erofs(void) { if (mount(device, MNTPOINT, fs_type, MS_REMOUNT | MS_RDONLY, NULL) < 0) { tst_brkm(TBROK | TERRNO, cleanup, "mount device:%s failed", device); } TEST(rename(TEST_EROFS, TEST_NEW_EROFS)); check_and_print(EROFS); if (TEST_RETURN == 0) SAFE_UNLINK(cleanup, TEST_NEW_EROFS); if (mount(device, MNTPOINT, fs_type, MS_REMOUNT, NULL) < 0) { tst_brkm(TBROK | TERRNO, cleanup, "remount device:%s failed", device); } }
int main(int argc, char *argv[]) { int lc, fd; int i = 0; char *file = NULL; struct stat stat; const char *msg = NULL; char filename[64]; char *progname = NULL; char *str_for_file = "abcdefghijklmnopqrstuvwxyz12345\n"; msg = parse_opts(argc, argv, NULL, NULL); if (msg) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); progname = *argv; sprintf(filename, "%s-out.%d", progname, getpid()); for (lc = 0; TEST_LOOPING(lc); lc++) { tst_count = 0; fd = open(filename, O_RDWR | O_CREAT, 0664); if (fd < 0) tst_brkm(TBROK | TERRNO, cleanup, "open failed"); #ifdef DEBUG tst_resm(TINFO, "filename = %s opened successfully", filename); #endif /* Writing 40 KB of random data into this file [32 * 1280 = 40960] */ for (i = 0; i < 1280; i++) if (write(fd, str_for_file, strlen(str_for_file)) == -1) tst_brkm(TBROK | TERRNO, cleanup, "write failed"); if (fstat(fd, &stat) == -1) tst_brkm(TBROK, cleanup, "fstat failed"); /* Map the input file into memory */ file = mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, fd, 0); if (file == MAP_FAILED) tst_brkm(TBROK, cleanup, "mmap failed"); /* (1) Test case for MADV_NORMAL */ TEST(madvise(file, stat.st_size, MADV_NORMAL)); check_and_print("MADV_NORMAL"); /* (2) Test case for MADV_RANDOM */ TEST(madvise(file, stat.st_size, MADV_RANDOM)); check_and_print("MADV_RANDOM"); /* (3) Test case for MADV_SEQUENTIAL */ TEST(madvise(file, stat.st_size, MADV_SEQUENTIAL)); check_and_print("MADV_SEQUENTIAL"); /* (4) Test case for MADV_WILLNEED */ TEST(madvise(file, stat.st_size, MADV_WILLNEED)); check_and_print("MADV_WILLNEED"); /* (5) Test case for MADV_DONTNEED */ TEST(madvise(file, stat.st_size, MADV_DONTNEED)); check_and_print("MADV_DONTNEED"); if (munmap(file, stat.st_size) == -1) tst_brkm(TBROK | TERRNO, cleanup, "munmap failed"); close(fd); } cleanup(); tst_exit(); }
int main(int argc, char *argv[]) { int lc, fd, pagesize; int i; unsigned long len; char *file, *low, *high; struct stat stat; char *ptr_memory_allocated = NULL; char *tmp_memory_allocated = NULL; char *msg = NULL; char filename[64]; char *progname = NULL; char *str_for_file = "abcdefghijklmnopqrstuvwxyz12345\n"; msg = parse_opts(argc, argv, NULL, NULL); if (msg) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); progname = *argv; sprintf(filename, "%s-out.%d", progname, getpid()); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; fd = open(filename, O_RDWR|O_CREAT, 0664); if (fd < 0) tst_brkm(TBROK, cleanup, "open failed"); #ifdef MM_DEBUG tst_resm(TINFO, "filename = %s opened successfully", filename); #endif pagesize = getpagesize(); /* Writing 16 pages of random data into this file */ for (i = 0; i < (pagesize / 2); i++) if (write(fd, str_for_file, strlen(str_for_file)) == -1) tst_brkm(TBROK|TERRNO, cleanup, "write failed"); if (fstat(fd, &stat) == -1) tst_brkm(TBROK, cleanup, "fstat failed"); file = mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, fd, 0); if (file == MAP_FAILED) tst_brkm(TBROK|TERRNO, cleanup, "mmap failed"); #ifdef MM_DEBUG tst_resm(TINFO, "The Page size is %d", pagesize); #endif /* Test Case 1 */ TEST(madvise(file + 100, stat.st_size, MADV_NORMAL)); check_and_print(EINVAL); /* Test Case 2 */ TEST(madvise(file, stat.st_size, 1212)); check_and_print(EINVAL); #if !defined(UCLINUX) /* Test Case 3 */ if (mlock((void *)file, stat.st_size) < 0) tst_brkm(TBROK, cleanup, "mlock failed"); TEST(madvise(file, stat.st_size, MADV_DONTNEED)); check_and_print(EINVAL); if (munmap(file, stat.st_size) == -1) tst_brkm(TBROK|TERRNO, cleanup, "munmap failed"); #endif /* if !defined(UCLINUX) */ /* Test Case 4 */ /* We cannot be sure, which region is mapped, which is * not, at runtime. * So, we will create two maps(of the same file), * unmap the map at higher address. * Now issue an madvise() on a region covering the * region which we unmapped. */ low = mmap(NULL, stat.st_size / 2, PROT_READ, MAP_SHARED, fd, 0); if (low == MAP_FAILED) tst_brkm(TBROK, cleanup, "mmap [low] failed"); high = mmap(NULL, stat.st_size / 2, PROT_READ, MAP_SHARED, fd, stat.st_size / 2); if (high == MAP_FAILED) tst_brkm(TBROK, cleanup, "mmap [high] failed"); /* Swap if necessary to make low < high */ if (low > high) { char *tmp; tmp = high; high = low; low = tmp; } len = (high - low) + pagesize; if (munmap(high, stat.st_size / 2) < 0) tst_brkm(TBROK|TERRNO, cleanup, "munmap [high] failed"); TEST(madvise(low, len, MADV_NORMAL)); check_and_print(ENOMEM); /* Test Case 5 */ /* Unmap the file map from low */ if (munmap(low, stat.st_size / 2) < 0) tst_brkm(TBROK|TERRNO, cleanup, "munmap [low] failed"); /* Create one memory segment using malloc */ ptr_memory_allocated = (char *)malloc(5 * pagesize); /* * Take temporary pointer for later use, freeing up the * original one. */ tmp_memory_allocated = ptr_memory_allocated; tmp_memory_allocated = (char *)(((unsigned long)tmp_memory_allocated + pagesize - 1) & ~(pagesize - 1)); TEST(madvise (tmp_memory_allocated, 5 * pagesize, MADV_WILLNEED)); check_and_print(EBADF); free((void *)ptr_memory_allocated); close(fd); } cleanup(); tst_exit(); }
int main(int argc, char *argv[]) { int lc, fd; char *file = NULL; struct stat stat; void *addr1; long shm_size = 0; char *msg = NULL; char filename[64]; char *progname = NULL; char *str_for_file = "abcdefghijklmnopqrstuvwxyz12345\n"; /* 32-byte string */ if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); setup(); progname = *argv; sprintf(filename, "%s-out.%d", progname, getpid()); for (lc = 0; TEST_LOOPING(lc); lc++) { Tst_count = 0; if ((fd = open(filename, O_RDWR | O_CREAT, 0664)) < 0) tst_brkm(TBROK, cleanup, "open failed"); #ifdef MM_DEBUG tst_resm(TINFO, "filename = %s opened successfully", filename); #endif /* Writing 40 KB of random data into this file [32 * 1280 = 40960] */ for (i = 0; i < 1280; i++) if (write(fd, str_for_file, strlen(str_for_file)) == -1) tst_brkm(TBROK|TERRNO, cleanup, "write failed"); if (fstat(fd, &stat) == -1) tst_brkm(TBROK, cleanup, "fstat failed"); if ((file = mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) tst_brkm(TBROK|TERRNO, cleanup, "mmap failed"); /* Allocate shared memory segment */ shm_size = get_shmmax(); #define min(a, b) ((a) < (b) ? (a) : (b)) if ((shmid1 = shmget(IPC_PRIVATE, min(1024*1024*1024, shm_size), IPC_CREAT|IPC_EXCL|0701)) == -1) tst_brkm(TBROK, cleanup, "shmget failed"); /* Attach shared memory segment to 0x22000000 address */ if ((addr1 = shmat(shmid1, (void *)0x22000000, 0)) == (void *) -1) tst_brkm(TBROK, cleanup, "shmat error"); /*(1) Test case for MADV_REMOVE */ TEST(madvise((void *)0x22000000, 4096, MADV_REMOVE)); check_and_print("MADV_REMOVE"); /*(2) Test case for MADV_DONTFORK */ TEST(madvise(file, (stat.st_size / 2), MADV_DONTFORK)); check_and_print("MADV_DONTFORK"); /*(3) Test case for MADV_DOFORK */ TEST(madvise(file, (stat.st_size / 2), MADV_DOFORK)); check_and_print("MADV_DOFORK"); /* Finally Unmapping the whole file */ if (munmap(file, stat.st_size) < 0) tst_brkm(TBROK|TERRNO, cleanup, "munmap failed"); close(fd); } cleanup(); tst_exit(); }
int main(int argc, char *argv[]) { int lc, fd; char *file = NULL; struct stat stat; char *msg = NULL; char filename[64]; char *progname = NULL; char *str_for_file = "abcdefghijklmnopqrstuvwxyz12345\n"; /* 32-byte string */ if ((msg = parse_opts(argc, argv, (option_t *) NULL, NULL)) != (char *)NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } /************************************************** * Perform global setup for test **************************************************/ setup(); /* Creating file in tmp directory for testing */ progname = *argv; sprintf(filename, "%s-out.%d", progname, getpid()); for (lc = 0; TEST_LOOPING(lc); lc++) { /* Reset Tst_count in case we are looping */ Tst_count = 0; /* Create a temporary file for testing */ if ((fd = open(filename, O_RDWR | O_CREAT, 0664)) < 0) { tst_brkm(TBROK, cleanup, "Could not open file \"%s\" with O_RDWR", filename); } #ifdef MM_DEBUG tst_resm(TINFO, "filename = %s opened successfully", filename); #endif /* Writing 40 KB of random data into this file [32 * 1280 = 40960] */ for (i = 0; i < 1280; i++) { if (write(fd, str_for_file, strlen(str_for_file)) < 0) { tst_brkm(TBROK, cleanup, "Could not write data to file \"%s\"", filename); } } /* Get file status for its size */ if (fstat(fd, &stat) < 0) { tst_brkm(TBROK, cleanup, "Could not stat file \"%s\"", filename); } /* Map the input file into memory */ if ((file = (char *)mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, fd, 0)) == (char *)-1) { tst_brkm(TBROK, cleanup, "Could not mmap file \"%s\"", filename); } /*(1) Test case for MADV_NORMAL */ TEST(madvise(file, stat.st_size, MADV_NORMAL)); check_and_print("MADV_NORMAL"); /*(2) Test case for MADV_RANDOM */ TEST(madvise(file, stat.st_size, MADV_RANDOM)); check_and_print("MADV_RANDOM"); /*(3) Test case for MADV_SEQUENTIAL */ TEST(madvise(file, stat.st_size, MADV_SEQUENTIAL)); check_and_print("MADV_SEQUENTIAL"); /*(4) Test case for MADV_WILLNEED */ TEST(madvise(file, stat.st_size, MADV_WILLNEED)); check_and_print("MADV_WILLNEED"); /*(5) Test case for MADV_DONTNEED */ TEST(madvise(file, stat.st_size, MADV_DONTNEED)); check_and_print("MADV_DONTNEED"); /* Finally Unmapping the whole file */ if (munmap(file, stat.st_size) < 0) { tst_brkm(TBROK, cleanup, "Could not unmap memory"); } close(fd); } cleanup(); return 0; }
int checkLoad (netsnmp_session * ss) { netsnmp_pdu *response; netsnmp_variable_list *vars; oid name[MAX_OID_LEN]; size_t name_length; oid root[MAX_OID_LEN]; size_t rootlen; int running; int exitval = 0; int cpunbr = 0; if (style == WINDOWS) { memmove (root, win_mib, sizeof (win_mib)); rootlen = sizeof (win_mib) / sizeof (oid); /* Style == LINUX */ } else { memmove (root, linux_mib, sizeof (linux_mib)); rootlen = sizeof (linux_mib) / sizeof (oid); } /* * get first object to start walk */ memmove (name, root, rootlen * sizeof (oid)); name_length = rootlen; running = 1; while (running) { if ((response = getResponse (name, name_length, ss, SNMP_MSG_GETNEXT)) == NULL) { printf ("Erreur SNMP : timeout\n"); return UNKNOWN; } if (response->errstat == SNMP_ERR_NOERROR) { /* * check variables */ for (vars = response->variables; vars; vars = vars->next_variable) { if ((vars->name_length < rootlen) || (memcmp (root, vars->name, rootlen * sizeof (oid)) != 0)) { /* * not part of this subtree */ running = 0; continue; } if (verbose) { print_variable (vars->name, vars->name_length, vars); } if (style == WINDOWS) { if (vars->type == ASN_INTEGER) { /* Allocation de 10 en 10 */ if (cpunbr == 0) { load = malloc (10 * sizeof (int)); } else if ((cpunbr % 10) == 0) { load = realloc (load, cpunbr + 10 * sizeof (int)); } load[cpunbr++] = (*(vars->val).integer); } } if (style == LINUX) { if (vars->type == ASN_OCTET_STR) { char *temp = (char *) malloc (1 + vars->val_len); memcpy (temp, vars->val.string, vars->val_len); temp[vars->val_len] = '\0'; if (strlen (temp) <= 5) { linload[cpunbr++] = strtod (temp, (char **) NULL); } free (temp); } } /* Test si ce n'est pas une exception */ if ((vars->type != SNMP_ENDOFMIBVIEW) && (vars->type != SNMP_NOSUCHOBJECT) && (vars->type != SNMP_NOSUCHINSTANCE)) { /* Et l'on avance dans la MIB :) */ memmove ((char *) name, (char *) vars->name, vars->name_length * sizeof (oid)); name_length = vars->name_length; } else /* * une exception , donc stop */ running = 0; } } else { /* * error in response, print it */ running = 0; printf ("Error in response"); return UNKNOWN; } if (response) snmp_free_pdu (response); } exitval = check_and_print (cpunbr); return exitval; }