init: init nachos hw01, should pass jenkins os_group_20_hw job but fail on os_group_20_ta job

This commit is contained in:
TA
2024-09-19 18:59:13 +08:00
commit 6ad2fa368f
267 changed files with 71977 additions and 0 deletions

69
code/test/sort.c Normal file
View File

@@ -0,0 +1,69 @@
/* sort.c
* Test program to sort a large number of integers.
*
* Intention is to stress virtual memory system.
*
* Ideally, we could read the unsorted array off of the file system,
* and store the result back to the file system!
*/
/*
#define UNIX
#define UNIX_DEBUG
*/
#ifdef UNIX
#include <stdio.h>
#define Exit exit
#else
#include "syscall.h"
#endif /* UNIX */
#define SIZE (1024)
int A[SIZE]; /* size of physical memory; with code, we'll run out of space!*/
int
main()
{
int i, j, tmp;
/* first initialize the array, in reverse sorted order */
for (i = 0; i < SIZE; i++) {
A[i] = (SIZE-1) - i;
}
/* then sort! */
for (i = 0; i < SIZE; i++) {
for (j = 0; j < (SIZE-1); j++) {
if (A[j] > A[j + 1]) { /* out of order -> need to swap ! */
tmp = A[j];
A[j] = A[j + 1];
A[j + 1] = tmp;
}
}
}
#ifdef UNIX_DEBUG
for (i=0; i<SIZE; i++) {
printf("%4d ", A[i]);
if (((i+1) % 15) == 0) {
printf("\n");
}
if (A[i] != i) {
fprintf(stderr, "Out of order A[%d] = %d\n", i, A[i]);
Exit(1);
}
}
printf("\n");
#endif /* UNIX_DEBUG */
for (i=0; i<SIZE; i++) {
if (A[i] != i) {
Exit(1);
}
}
Exit(0);
}