-
Notifications
You must be signed in to change notification settings - Fork 18
/
api-test.c
105 lines (87 loc) · 2.91 KB
/
api-test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* File: api-test.c
* Author: Andy Sayler
* http://www.andysayler.com
* Adopted From: Dr. Alva Couch
* http://www.cs.tufts.edu/~couch/
*
* Project: CSCI 3753 Programming Assignment 4
* Create Date: 2012/04/11
* Modify Date: 2012/04/11
* Description:
* This file contains a number of calls to the simulator API
* to confirm the behavior of the simulator is specific situations.
*/
#include <stdio.h>
#include <stdlib.h>
#include "simulator.h"
#define MAXITERATIONS 5
void pageit(Pentry q[MAXPROCESSES]) {
/* Static Vars */
static int tick = 0;
static int outTestRun = 0;
static int inTestRun = 0;
static int iterations = 0;
/* Local vars */
int testProc = 0;
int testPage = 0;
int pageinret = -1;
int pageoutret = -1;
/* All pages are swapped out on start */
if(q[testProc].pages[testPage]){
/* Page is swapped in */
if(!inTestRun){
fprintf(stdout, "%4d - %d:%d is swapped in\n", tick, testProc, testPage);
fprintf(stdout, "%4d - q[%d].pages[%d] = %ld\n",
tick, testProc, testPage, q[testProc].pages[testPage]);
pageinret = pagein(testProc, testPage);
fprintf(stdout, "%4d - pagein(%d, %d) returns %d\n",
tick, testProc, testPage, pageinret);
fprintf(stdout, "%4d - q[%d].pages[%d] = %ld\n",
tick, testProc, testPage, q[testProc].pages[testPage]);
pageoutret = pageout(testProc, testPage);
fprintf(stdout, "%4d - pageout(%d, %d) returns %d\n",
tick, testProc, testPage, pageoutret);
if(pageoutret){
/* Wait for pageout to complete */
inTestRun = 1;
outTestRun = 0;
iterations++;
}
fprintf(stdout, "%4d - q[%d].pages[%d] = %ld\n",
tick, testProc, testPage, q[testProc].pages[testPage]);
}
}
else{
/* Page is swapped out */
if(!outTestRun){
fprintf(stdout, "%4d - %d:%d is swapped out\n", tick, testProc, testPage);
fprintf(stdout, "%4d - q[%d].pages[%d] = %ld\n",
tick, testProc, testPage, q[testProc].pages[testPage]);
pageoutret = pageout(testProc, testPage);
fprintf(stdout, "%4d - pageout(%d, %d) returns %d\n",
tick, testProc, testPage, pageoutret);
fprintf(stdout, "%4d - q[%d].pages[%d] = %ld\n",
tick, testProc, testPage, q[testProc].pages[testPage]);
pageinret = pagein(testProc, testPage);
fprintf(stdout, "%4d - pagein(%d, %d) returns %d\n",
tick, testProc, testPage, pageinret);
if(pageinret){
/* Wait for pagein to complete */
outTestRun = 1;
inTestRun = 0;
iterations++;
}else{
fprintf(stdout, "%4d - pageout in progress...\n", tick);
}
fprintf(stdout, "%4d - q[%d].pages[%d] = %ld\n",
tick, testProc, testPage, q[testProc].pages[testPage]);
}
}
/* Run test for I state change iterations */
if(iterations > MAXITERATIONS){
fprintf(stdout, "API Test Exiting\n");
exit(EXIT_SUCCESS);
}
tick++;
}