Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "types.h"
- #include "user.h"
- #define PGSIZE 4096
- #define ASSERT(cond, ...) \
- if(!cond){ \
- printf(1, "failed!!!! %s:%d - ", __FUNCTION__, __LINE__); \
- printf(1, "\n"); \
- exit(); \
- }
- int pgdir_testing() {
- malloc(10 * 1024 * PGSIZE);
- return -1;
- }
- int fork_test() {
- #define SOME_SIZE 5
- int proccssss = 10;
- int i = 0;
- int j = 0;
- int pid;
- printf(1, "calling malloc\n");
- int * arr = malloc(4 * SOME_SIZE);
- for (i = 0; i < SOME_SIZE; i++) {
- arr[i] = i;
- }
- for (i = 0; i < proccssss; i++) {
- printf(1, "forking: %d\n", i);
- if ((pid = fork()) == 0) {
- for (j = 0; j < SOME_SIZE; j++) {
- ASSERT(arr[j] == j);
- }
- exit();
- } else {
- ASSERT(wait() == pid);
- }
- }
- return 0;
- }
- int test_malloc() {
- malloc(100 * PGSIZE);
- return 0;
- }
- void fib(int n) {
- int i = 1;
- printf(1, "%d\n", n);
- i++;
- fib(n + 1);
- }
- int do_stackoverflow() {
- int pid;
- if ((pid = fork()) == 0) {
- fib(0);
- } else {
- ASSERT(wait() == pid);
- }
- return 0;
- }
- int try_crash_malloc() {
- unsigned int ty = 1024 * 1024 * 1024;
- ASSERT(malloc(ty) != 0);
- ASSERT(malloc(ty + 100) == 0);
- return 0;
- }
- int
- main(int argc, char *argv[]) {
- test_malloc();
- pgdir_testing();
- fork_test();
- do_stackoverflow();
- try_crash_malloc();
- exit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement