示例#1
0
文件: main.c 项目: burrows-labs/bjail
int
main(int argc, char **argv)
{
#ifdef TEST_BUILD
    {
        printf("running tests!\n\n");
        // separate processes are needed as we want to do different chroots
        int pid = fork();
        if (0 == pid) {
            assert(true == test_read_only_chroot());
        } else {
            const char *const dirname = "./tdd/";
            umount(dirname);
            rmdir(dirname);
            assert(0 == mkdir(dirname, 0777));
            assert(true == prepareSandbox(dirname));
            assert(true == testFileCreation());
            assert(true == testFork());
            assert(true == testMem());
        }
    }

    printf("success!\n");
    return 0;
#else

    if (argc < 3) {
        fprintf(stderr, "usage: %s <chroot-path> <sandbox-me> <args ...>\n", argv[0]);
        return 1;
    }

    if (0 != getuid()) {
      fprintf(stderr, "must be root!\n");
      return 1;
    }

    assert(true == prepareSandbox(argv[1]));

    // create argument parameter
    char **args = calloc(sizeof(char *), argc - 1);
    if (!args) {
        fprintf(stderr, "calloc failed!\n");
        return 1;
    }
    args[0] = argv[2];
    for (size_t i = 3; i < argc; ++i) {
        args[i-2] = strdup(argv[i]);
    }
    args[argc-2] = NULL;

    execv(argv[2], args);
    fprintf(stderr, "execv failed!\n");

    return 1;
#endif
}
示例#2
0
int main()
{
        printf("Testing SCHED_OTHER process... ");
        testOther();

        printf("Testing making son process LSHORT... ");
        testMakeSonLshort();

        printf("Testing bad parameters... ");
        testBadParams();

        printf("Testing new System Calls... ");
        testSysCalls();

        printf("Testing becoming overdue... ");
        testBecomingOverdue();

        printf("Testing fork... ");
        testFork();

        printf("Testing Overdues Round-Robin... \n");
        testOverdueRoundRobin();

        printf("Testing race: RT vs. LSHORT (RT is supposed to win)\n");
        testScheduleRealTimeOverLShort();

        printf("Testing race: RT vs. LSHORT #2 (RT is supposed to win)\n");
        testScheduleRealTimeOverLShort2();

        printf("Testing race: LSHORT vs. OTHER (LSHORT is supposed to win)\n");
        testScheduleLShortOverOther();

        printf("Testing race: LSHORT vs. OTHER #2(LSHORT is supposed to win)\n");
        testScheduleLShortOverOther2();

        printf("Testing race: OTHER vs. OVERDUE (OTHER is supposed to win)\n");
        testScheduleOtherOverOverdue();

        printf("Testing race: OTHER vs. OVERDUE #2 (OTHER is supposed to win)\n");
        testScheduleOtherOverOverdue2();

        printf("Testing making this process LSHORT... ");
        testMakeLshort();
        printf("Success!\n");
        return 0;
}