diff --git a/userspace/programs/Shell/main.cpp b/userspace/programs/Shell/main.cpp index bf1927d0..449afc6a 100644 --- a/userspace/programs/Shell/main.cpp +++ b/userspace/programs/Shell/main.cpp @@ -353,187 +353,6 @@ BAN::Optional execute_builtin(BAN::Vector& args, int fd_in, in execl("/bin/Terminal", "Terminal", NULL); waitpid(pid, nullptr, 0); } - else if (args.front() == "page-fault-test"_sv) - { - volatile int* ptr = nullptr; - *ptr = 0; - } - else if (args.front() == "kill-test"_sv) - { - pid_t pid = fork(); - if (pid == 0) - { - fprintf(fout, "child\n"); - for (;;); - } - if (pid == -1) - { - perror("fork"); - return 1; - } - - sleep(1); - if (kill(pid, SIGSEGV) == -1) - { - perror("kill"); - return 1; - } - } - else if (args.front() == "signal-test"_sv) - { - pid_t pid = fork(); - if (pid == 0) - { - dup2(fileno(fout), STDOUT_FILENO); - if (signal(SIGSEGV, [](int) { printf("SIGSEGV\n"); }) == SIG_ERR) - { - perror("signal"); - exit(1); - } - printf("child\n"); - for (;;); - } - if (pid == -1) - { - perror("fork"); - return 1; - } - - sleep(1); - if (kill(pid, SIGSEGV) == -1) - { - perror("kill"); - return 1; - } - - sleep(1); - if (kill(pid, SIGTERM) == -1) - { - perror("kill"); - return 1; - } - } - else if (args.front() == "printf-test"_sv) - { - fprintf(fout, " 0.0: %f\n", 0.0f); - fprintf(fout, " 123.0: %f\n", 123.0f); - fprintf(fout, " 0.123: %f\n", 0.123f); - fprintf(fout, " NAN: %f\n", NAN); - fprintf(fout, "+INF: %f\n", INFINITY); - fprintf(fout, "-INF: %f\n", -INFINITY); - } - else if (args.front() == "cd"_sv) - { - if (args.size() > 2) - { - fprintf(fout, "cd: too many arguments\n"); - return 1; - } - - BAN::StringView path; - - if (args.size() == 1) - { - if (const char* path_env = getenv("HOME")) - path = path_env; - else - return 0; - } - else - path = args[1]; - - if (chdir(path.data()) == -1) - ERROR_RETURN("chdir", 1); - } - else if (args.front() == "time"_sv) - { - args.remove(0); - - timespec start, end; - - if (clock_gettime(CLOCK_MONOTONIC, &start) == -1) - ERROR_RETURN("clock_gettime", 1); - - int ret = execute_command(args, fd_in, fd_out); - - if (clock_gettime(CLOCK_MONOTONIC, &end) == -1) - ERROR_RETURN("clock_gettime", 1); - - uint64_t total_ns = 0; - total_ns += (end.tv_sec - start.tv_sec) * 1'000'000'000; - total_ns += end.tv_nsec - start.tv_nsec; - - int secs = total_ns / 1'000'000'000; - int msecs = (total_ns % 1'000'000'000) / 1'000'000; - - fprintf(fout, "took %d.%03d s\n", secs, msecs); - - return ret; - } - else if (args.front() == "test-strtox") - { -#define TEST(num, base) do { errno = 0; printf("strtol(\"" num "\", nullptr, " #base ") = %ld ", strtol(num, nullptr, base)); puts(errno ? strerrorname_np(errno) : ""); } while (false) - TEST("0", 10); - TEST("", 10); - TEST("+", 10); - TEST("123", 10); - TEST("-123", 10); - TEST("7fffffffffffffff", 10); - TEST("7fffffffffffffff", 16); - TEST("8000000000000000", 16); - TEST("-8000000000000000", 16); - TEST("-8000000000000001", 16); - TEST("123", 0); - TEST("0123", 0); - TEST("0x123", 0); - TEST("123", 1); - TEST("hello", 10); - TEST("hello", 36); -#undef TEST -#define TEST(num, base) do { errno = 0; printf("strtoul(\"" num "\", nullptr, " #base ") = %lu ", strtoul(num, nullptr, base)); puts(errno ? strerrorname_np(errno) : ""); } while (false) - TEST("0", 10); - TEST("123", 10); - TEST("-123", 10); - TEST("-1", 10); - TEST("fffffffffffffff", 16); - TEST("ffffffffffffffff", 16); - TEST("10000000000000000", 16); -#undef TEST -#if __enable_sse -#define TEST(num) do { errno = 0; printf("strtod(\"" num "\", nullptr) = %e ", strtod(num, nullptr)); puts(errno ? strerrorname_np(errno) : ""); } while (false) - TEST("0"); - TEST(".1"); - TEST("1."); - TEST("0x.1"); - TEST("0x1."); - TEST("123"); - TEST("-123"); - TEST("0x123"); - TEST("123.456"); - TEST("-123.456"); - TEST("1.2e5"); - TEST("1.e5"); - TEST(".2e5"); - TEST("0x1.2p5"); - TEST("0x1.p5"); - TEST("0x.2p5"); - TEST("1e999"); - TEST("-1e999"); - TEST("1e308"); - TEST("1e-307"); - TEST("1e309"); - TEST("1e-308"); - TEST("0.00000000001e312"); - TEST("1000000000000e-312"); - TEST("0e999"); - TEST("0e-999"); - TEST("1237754.446f"); - TEST("inf"); - TEST("-inf"); - TEST("nan"); -#undef TEST -#endif - } else { return {};