summaryrefslogtreecommitdiff
path: root/user/pgtbltest.c
diff options
context:
space:
mode:
authorMole Shang <[email protected]>2024-02-17 11:55:33 +0800
committerMole Shang <[email protected]>2024-02-17 12:22:07 +0800
commite8e0a7b4c97064eb5e9415726d7e38aaceccd3fd (patch)
treefb42ba5be7a8ae608b968266f62fd71fa889a89d /user/pgtbltest.c
parenta6af72924b115c1177d18d9b1eaba56623e4248b (diff)
parentd85aec2689c4250d0384904bdc11aa618c726bec (diff)
downloadxv6-labs-e8e0a7b4c97064eb5e9415726d7e38aaceccd3fd.tar.gz
xv6-labs-e8e0a7b4c97064eb5e9415726d7e38aaceccd3fd.tar.bz2
xv6-labs-e8e0a7b4c97064eb5e9415726d7e38aaceccd3fd.zip
Merge branch 'thread' into fs
Conflicts: .gitignore Makefile conf/lab.mk kernel/param.h
Diffstat (limited to 'user/pgtbltest.c')
-rw-r--r--user/pgtbltest.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/user/pgtbltest.c b/user/pgtbltest.c
new file mode 100644
index 0000000..bce158a
--- /dev/null
+++ b/user/pgtbltest.c
@@ -0,0 +1,70 @@
+#include "kernel/param.h"
+#include "kernel/fcntl.h"
+#include "kernel/types.h"
+#include "kernel/riscv.h"
+#include "user/user.h"
+
+void ugetpid_test();
+void pgaccess_test();
+
+int
+main(int argc, char *argv[])
+{
+ ugetpid_test();
+ pgaccess_test();
+ printf("pgtbltest: all tests succeeded\n");
+ exit(0);
+}
+
+char *testname = "???";
+
+void
+err(char *why)
+{
+ printf("pgtbltest: %s failed: %s, pid=%d\n", testname, why, getpid());
+ exit(1);
+}
+
+void
+ugetpid_test()
+{
+ int i;
+
+ printf("ugetpid_test starting\n");
+ testname = "ugetpid_test";
+
+ for (i = 0; i < 64; i++) {
+ int ret = fork();
+ if (ret != 0) {
+ wait(&ret);
+ if (ret != 0)
+ exit(1);
+ continue;
+ }
+ if (getpid() != ugetpid())
+ err("missmatched PID");
+ exit(0);
+ }
+ printf("ugetpid_test: OK\n");
+}
+
+void
+pgaccess_test()
+{
+ char *buf;
+ unsigned int abits;
+ printf("pgaccess_test starting\n");
+ testname = "pgaccess_test";
+ buf = malloc(32 * PGSIZE);
+ if (pgaccess(buf, 32, &abits) < 0)
+ err("pgaccess failed");
+ buf[PGSIZE * 1] += 1;
+ buf[PGSIZE * 2] += 1;
+ buf[PGSIZE * 30] += 1;
+ if (pgaccess(buf, 32, &abits) < 0)
+ err("pgaccess failed");
+ if (abits != ((1 << 1) | (1 << 2) | (1 << 30)))
+ err("incorrect access bits set");
+ free(buf);
+ printf("pgaccess_test: OK\n");
+}