add CPUTest
This commit is contained in:
parent
be169c2c20
commit
0e978aca7e
Binary file not shown.
|
@ -1,2 +0,0 @@
|
|||
# CPUTestcases
|
||||
测试用例
|
|
@ -1,64 +0,0 @@
|
|||
#include "trap.h"
|
||||
#include "stdio.h"
|
||||
#define VMEM ((char *)0xc0000000)
|
||||
int main()
|
||||
{
|
||||
char* vga = VMEM + 320 + 80;
|
||||
volatile int * x = (int *)0x01000000;
|
||||
*x = 0x0c0c0c0c;
|
||||
x = (int *)0x02000000;
|
||||
*x = 0xffff0c0c;
|
||||
x = (int *)0x03000000;
|
||||
*x = 0xffffffff;
|
||||
x = (int *)0x04000000;
|
||||
*x = 0x0c0cffff;
|
||||
x = (int *)0x05000000;
|
||||
*x = 0x77777777;
|
||||
x = (int *)0x06000000;
|
||||
*x = 0x55555555;
|
||||
if(*((int *)0x01000000) != 0x0c0c0c0c) {
|
||||
bad();
|
||||
}
|
||||
|
||||
if(*((int *)0x02000000) != 0xffff0c0c) {
|
||||
bad();
|
||||
|
||||
}
|
||||
|
||||
if(*((int *)0x03000000) != 0xffffffff) {
|
||||
bad();
|
||||
}
|
||||
|
||||
if(*((int *)0x04000000) != 0x0c0cffff) {
|
||||
bad();
|
||||
}
|
||||
|
||||
if(*((int *)0x05000000) != 0x77777777) {
|
||||
bad();
|
||||
}
|
||||
|
||||
if(*((int *)0x06000000) != 0x55555555) {
|
||||
bad();
|
||||
}
|
||||
|
||||
put_hex(*((int *)0x01000000), vga);
|
||||
vga += 160;
|
||||
|
||||
put_hex(*((int *)0x02000000), vga);
|
||||
vga += 160;
|
||||
|
||||
put_hex(*((int *)0x03000000), vga);
|
||||
vga += 160;
|
||||
|
||||
put_hex(*((int *)0x04000000), vga);
|
||||
vga += 160;
|
||||
|
||||
put_hex(*((int *)0x05000000), vga);
|
||||
vga += 160;
|
||||
|
||||
put_hex(*((int *)0x06000000), vga);
|
||||
vga += 160;
|
||||
good();
|
||||
|
||||
return good();;
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
#include "trap.h"
|
||||
#include "stdio.h"
|
||||
|
||||
void swap(volatile int arr[], int i, int j) {
|
||||
int temp = arr[i];
|
||||
arr[i] = arr[j];
|
||||
arr[j] = temp;
|
||||
}
|
||||
// low-high in increasing order
|
||||
void quickSort3Ways(volatile int arr[], int lowIndex, int highIndex) {
|
||||
if(lowIndex >= highIndex) return;
|
||||
int i = lowIndex + 1;
|
||||
int pivot_value = arr[lowIndex];
|
||||
int lt = lowIndex;
|
||||
int gt = highIndex;
|
||||
while(i <= gt) {
|
||||
if(arr[i] < pivot_value) {
|
||||
swap(arr, i++, lt++);
|
||||
}
|
||||
else if(arr[i] > pivot_value) {
|
||||
swap(arr, i, gt--);
|
||||
}
|
||||
else {
|
||||
i ++;
|
||||
}
|
||||
}
|
||||
quickSort3Ways(arr, lowIndex, lt - 1);
|
||||
quickSort3Ways(arr, gt + 1, highIndex);
|
||||
}
|
||||
|
||||
#define VMEM ((char *)0xc0000000)
|
||||
|
||||
int main() {
|
||||
char* vga = VMEM + 320 + 80;
|
||||
volatile int arr[100];
|
||||
int j;
|
||||
put_hex((int )&arr[0], vga);
|
||||
vga += 160;
|
||||
for(j = 0; j < 100; j += 1) {
|
||||
arr[j] = 200 - j;
|
||||
}
|
||||
quickSort3Ways(arr, 0, 99);
|
||||
|
||||
for(j = 0; j < 50; j ++) {
|
||||
put_hex(arr[j], vga);
|
||||
vga += 160;
|
||||
}
|
||||
vga += 210;
|
||||
for(;j < 100; j ++) {
|
||||
put_hex(arr[j], vga);
|
||||
vga += 160;
|
||||
}
|
||||
good();
|
||||
return good();
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
#ifndef TRAP_H
|
||||
#define TRAP_H
|
||||
|
||||
// NOTE: only for self-correctness check!
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define ASSERT(x) do { \
|
||||
if (!(x)) bad(); \
|
||||
} while (0)
|
||||
|
||||
|
||||
static void good() { puts("HIT GOOD TRAP"); exit(0); }
|
||||
static void bad() { puts("HIT BAD TRAP"); exit(-1); }
|
||||
|
||||
#endif // TRAP_H
|
Loading…
Reference in New Issue