#include "kernel/types.h" #include "kernel/stat.h" #include "user/user.h" void test_dirtypages() { printf("dirtypages test starting\n"); // Allocate some pages char *buf = malloc(32 * 4096); // 32 pages if(buf == 0) { printf("malloc failed\n"); exit(1); } // Clear dirty bits first by calling dirtypages unsigned int dbits; if (dirtypages(buf, 32, &dbits) < 0) { printf("dirtypages failed\n"); exit(1); } printf("Initial dirty bits cleared: 0x%x\n", dbits); // Write to some pages to make them dirty buf[0] = 1; // Page 0 buf[4096 * 5] = 1; // Page 5 buf[4096 * 10] = 1; // Page 10 // Check dirty pages if (dirtypages(buf, 32, &dbits) < 0) { printf("dirtypages failed\n"); exit(1); } printf("Dirty bits after writes: 0x%x\n", dbits); // Check if the expected pages are marked as dirty if (dbits & (1 << 0)) printf("Page 0 is dirty (expected)\n"); if (dbits & (1 << 5)) printf("Page 5 is dirty (expected)\n"); if (dbits & (1 << 10)) printf("Page 10 is dirty (expected)\n"); // Check again - dirty bits should be cleared now if (dirtypages(buf, 32, &dbits) < 0) { printf("dirtypages failed\n"); exit(1); } printf("Dirty bits after clearing: 0x%x (should be 0)\n", dbits); free(buf); printf("dirtypages test: OK\n"); } int main(int argc, char *argv[]) { test_dirtypages(); exit(0); }