ci: init
All checks were successful
Test openperf / checkout_repos (native, stream) (push) Successful in 1m53s

This commit is contained in:
xinyangli 2024-11-09 14:10:13 +08:00
parent d4748ac579
commit e96f54dbe6
Signed by: xin
SSH key fingerprint: SHA256:UU5pRTl7NiLFJbWJZa+snLylZSXIz5rgHmwjzv8v4oE
6 changed files with 157 additions and 488 deletions

View file

@ -0,0 +1,53 @@
name: Test openperf
on: [push, pull_request, workflow_dispatch]
jobs:
checkout_repos:
runs-on: nix
strategy:
matrix:
arch: ["native"] # Define architectures here
test_name: ["stream"] # Define test names here
steps:
- name: Checkout Main Repo (openperf)
uses: actions/checkout@v4
with:
path: openperf
- name: Checkout Abstract Machine Repo
uses: actions/checkout@v4
with:
ssh-key: '${{ secrets.DEPLOY_KEY }}'
ssh-user: 'forgejo'
ssh-known-hosts: 'git.xinyang.life ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICctRGZWr5+pxPh+8ABY4kjC57khQzOpXNz3CPaEDZuO'
repository: openperf/abstract-machine
path: abstract-machine
- name: Checkout Nemu Repo
uses: actions/checkout@v4
with:
ssh-key: '${{ secrets.DEPLOY_KEY }}'
ssh-user: 'forgejo'
ssh-known-hosts: 'git.xinyang.life ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAICctRGZWr5+pxPh+8ABY4kjC57khQzOpXNz3CPaEDZuO'
repository: openperf/nemu
path: nemu
- name: Build nix environment and dependencies
working-directory: openperf
env:
AM_HOME: "${{ github.workspace }}/abstract-machine"
NEMU_HOME: "${{ github.workspace }}/nemu"
run: |
nix develop .#native --impure --command make ARCH=${{ matrix.arch }} ALL=common
- name: Build and Run with Matrix
working-directory: openperf
env:
AM_HOME: "${{ github.workspace }}/abstract-machine"
NEMU_HOME: "${{ github.workspace }}/nemu"
run: |
nix develop .#native --impure --command make ARCH=${{ matrix.arch }} ALL=${{ matrix.test_name }} run

3
.gitignore vendored
View file

@ -16,4 +16,5 @@ _*
*~
build/
!.gitignore
.vscode
.vscode
abstract-machine/

View file

@ -53,11 +53,6 @@ $(ALL): %: $(BENCH_LIBS)
run: $(BENCH_LIBS) all
@cat $(RESULT)
@echo "============================================="
@if grep -q -i -e "fail" "$(RESULT)"; then \
echo "OpenPerf FAIL"; \
else \
echo "OpenPerf PASS"; \
fi
@awk '\
{ \
h = min = s = ms = us = 0;\
@ -76,7 +71,15 @@ run: $(BENCH_LIBS) all
us; \
} \
' $(RESULT)
@rm $(RESULT)
@if grep -q -i -e "fail" "$(RESULT)"; then \
echo "OpenPerf FAIL"; \
rm $(RESULT); \
exit 1; \
else \
echo "OpenPerf PASS"; \
rm $(RESULT); \
exit 0; \
fi
CLEAN_ALL = $(dir $(shell find . -mindepth 2 -name Makefile))
clean-all: $(CLEAN_ALL)

27
flake.lock generated Normal file
View file

@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1729658218,
"narHash": "sha256-9Rg+AqLqvqqJniP/OQB3GtgXoAd8IlazsHp97va042Y=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "dfffb2e7a52d29a0ef8e21ec8a0f30487b227f1a",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

66
flake.nix Normal file
View file

@ -0,0 +1,66 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
outputs =
{ self, nixpkgs, ... }:
{
devShells.x86_64-linux =
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
crossSystem = {
config = "riscv32-none-none-elf";
gcc = {
abi = "ilp32";
arch = "rv32i";
};
};
localSystem = "x86_64-linux";
rv32CrossPkgs = import nixpkgs {
inherit localSystem crossSystem;
};
rv32LLVMCrossPkgs = import nixpkgs {
inherit localSystem;
crossSystem = crossSystem // {
useLLVM = true;
};
};
bareClangStdenv =
with rv32LLVMCrossPkgs;
overrideCC clangStdenv buildPackages.llvmPackages.clangNoLibc;
nemuDepsBuildBuild = with pkgs; [
gnumake
SDL2
pkg-config
bison
flex
ncurses
readline
libllvm
gcc
clang
];
in
{
nemu = rv32CrossPkgs.mkDerivation {
name = "openperf";
depsBuildBuild = nemuDepsBuildBuild;
};
nemu-clang = bareClangStdenv.mkDerivation {
name = "openperf";
depsBuildBuild = nemuDepsBuildBuild;
};
native = pkgs.stdenv.mkDerivation {
name = "openperf";
buildInputs = with pkgs; [
gnumake
SDL2
];
};
};
};
}

View file

@ -1,481 +0,0 @@
#include <am.h>
#include <klib.h>
#include <klib-macros.h>
#include <stdarg.h>
#define ZEROPAD 1
#define SIGN 2
#define PLUS 4
#define SPACE 8
#define LEFT 16
#define SPECIAL 32
#define LARGE 64
#define is_digit(c) ((c) >= '0' && (c) <= '9')
#define SZ_NUM_BUF 32
static char sprint_fe[SZ_NUM_BUF+1];
#define PRINT_BUF_SIZE 512
static const char *digits = "0123456789abcdefghijklmnopqrstuvwxyz";
static const char *upper_digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static size_t strnlen(const char *s, size_t count)
{
const char *sc;
for (sc = s; *sc != '\0' && count--; ++sc);
return sc - s;
}
static int skip_atoi(const char **s)
{
int i = 0;
while (is_digit(**s)) i = i*10 + *((*s)++) - '0';
return i;
}
static char *number(char *str, long num, int base, int size, int precision, int type)
{
char c, sign, tmp[66];
const char *dig = digits;
int i;
if (type & LARGE) dig = upper_digits;
if (type & LEFT) type &= ~ZEROPAD;
if (base < 2 || base > 36) return 0;
c = (type & ZEROPAD) ? '0' : ' ';
sign = 0;
if (type & SIGN)
{
if (num < 0)
{
sign = '-';
num = -num;
size--;
}
else if (type & PLUS)
{
sign = '+';
size--;
}
else if (type & SPACE)
{
sign = ' ';
size--;
}
}
if (type & SPECIAL)
{
if (base == 16)
size -= 2;
else if (base == 8)
size--;
}
i = 0;
if (num == 0)
tmp[i++] = '0';
else
{
while (num != 0)
{
tmp[i++] = dig[((unsigned long) num) % (unsigned) base];
num = ((unsigned long) num) / (unsigned) base;
}
}
if (i > precision) precision = i;
size -= precision;
if (!(type & (ZEROPAD | LEFT))) while (size-- > 0) *str++ = ' ';
if (sign) *str++ = sign;
if (type & SPECIAL)
{
if (base == 8)
*str++ = '0';//0
else if (base == 16)
{
*str++ = '0';
*str++ = digits[33];//0x
}
}
if (!(type & LEFT))
while (size-- > 0) *str++ = c;
while (i < precision--) *str++ = '0';
while (i-- > 0) *str++ = tmp[i];
while (size-- > 0) *str++ = ' ';
return str;
}
static int ilog10(double n)
{
int rv = 0;
while (n >= 10)
{
if (n >= 100000)
{
n /= 100000; rv += 5;
}
else
{
n /= 10; rv++;
}
}
while (n < 1)
{
if (n < 0.00001)
{
n *= 100000; rv -= 5;
}
else
{
n *= 10; rv--;
}
}
return rv;
}
static double i10x(int n)
{
double rv = 1;
while (n > 0)
{
if (n >= 5)
{
rv *= 100000; n -= 5;
}
else
{
rv *= 10; n--;
}
}
while (n < 0)
{ /* Right shift */
if (n <= -5)
{
rv /= 100000; n += 5;
}
else
{
rv /= 10; n++;
}
}
return rv;
}
static void ftoa(char* buf, double val, int prec, char fmt)
{
int d;
int e = 0, m = 0;
char sign = 0;
double w;
const char *er = 0;
const char ds = '.';
unsigned int *pu=(unsigned int *)&val;
if(((pu[1]&0x7ff00000)==0x7ff00000)&&(((pu[1]&0xfffff)!=0)||(pu[0]!=0)))
{
er = "NaN";
}
else
{
if (prec < 0) prec = 6;
if (val < 0)
{
val = 0 - val;
sign = '-';
}
else
{
sign = '+';
}
if(((pu[1]&0x7fffffff) ==0x7ff00000)&&(pu[0] == 0))
{
er = "INF";
}
else
{
if (fmt == 'f')
{
val += i10x(0 - prec) / 2;
m = ilog10(val);
if (m < 0) m = 0;
if (m + prec + 3 >= SZ_NUM_BUF) er = "OV";
}
else
{
if (val != 0)
{
val += i10x(ilog10(val) - prec) / 2;
e = ilog10(val);
if (e > 99 || prec + 7 >= SZ_NUM_BUF)
{
er = "OV";
}
else
{
if (e < -99) e = -99;
val /= i10x(e);
}
}
}
}
if (!er)
{
if (sign == '-')
*buf++ = sign;
do
{
if (m == -1)
*buf++ = ds;
w = i10x(m);
d = (int)(val / w); val -= d * w;
*buf++ = (char)('0' + d);
} while (--m >= -prec);
if (fmt != 'f')
{
*buf++ = (char)fmt;
if (e < 0) {
e = 0 - e; *buf++ = '-';
}
else {
*buf++ = '+';
}
*buf++ = (char)('0' + e / 10);
*buf++ = (char)('0' + e % 10);
}
}
}
if (er)
{
if (sign) *buf++ = sign;
do
{
*buf++ = *er++;
} while (*er);
}
*buf = 0;
}
int bench_vsprintf(char *buf, const char *fmt, va_list args)
{
int len = 0;
unsigned long long num = 0;
int i = 0, j = 0, base = 0;
char * str;
const char *s;
int flags; /* flags to number() */
int field_width; /* width of output field */
int precision; /* min. # of digits for integers; max number of chars for from string */
int qualifier; /* 'h', 'l', or 'L' for integer fields */
/* 'z' support added 23/7/1999 S.H. */
/* 'z' changed to 'Z' --davidm 1/25/99 */
for (str=buf ; *fmt ; ++fmt)
{
if (*fmt != '%')
{
*str++ = *fmt;
continue;
}
/* flags */
flags = 0;
repeat:
++fmt;
switch (*fmt)
{
case '-': flags |= LEFT; goto repeat;
case '+': flags |= PLUS; goto repeat;
case ' ': flags |= SPACE; goto repeat;
case '#': flags |= SPECIAL; goto repeat;
case '0': flags |= ZEROPAD; goto repeat;
}
field_width = -1;
if ('0' <= *fmt && *fmt <= '9')
field_width = skip_atoi(&fmt);
else if (*fmt == '*')
{
++fmt;/*skip '*' */
/* it's the next argument */
field_width = va_arg(args, int);
if (field_width < 0) {
field_width = -field_width;
flags |= LEFT;
}
}
precision = -1;
if (*fmt == '.')
{
++fmt;
if ('0' <= *fmt && *fmt <= '9')
precision = skip_atoi(&fmt);
else if (*fmt == '*')
{
++fmt;
/* it's the next argument */
precision = va_arg(args, int);
}
if (precision < 0)
precision = 0;
}
qualifier = -1;
if (*fmt == 'l' && *(fmt + 1) == 'l')
{
qualifier = 'q';
fmt += 2;
}
else if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L'|| *fmt == 'Z')
{
qualifier = *fmt;
++fmt;
}
/* default base */
base = 10;
switch (*fmt)
{
case 'c':
if (!(flags & LEFT))
while (--field_width > 0)
*str++ = ' ';
*str++ = (unsigned char) va_arg(args, int);
while (--field_width > 0)
*str++ = ' ';
continue;
case 's':
s = va_arg(args, char *);
if (!s)
s = "";
len = strnlen(s, precision);
if (!(flags & LEFT))
while (len < field_width--)
*str++ = ' ';
for (i = 0; i < len; ++i)
*str++ = *s++;
while (len < field_width--)
*str++ = ' ';
continue;
case 'p':
if (field_width == -1)
{
field_width = 2*sizeof(void *);
flags |= ZEROPAD;
}
str = number(str,(unsigned long) va_arg(args, void *), 16,field_width, precision, flags);
continue;
case 'n':
if (qualifier == 'l')
{
long * ip = va_arg(args, long *);
*ip = (str - buf);
}
else if (qualifier == 'Z')
{
size_t * ip = va_arg(args, size_t *);
*ip = (str - buf);
}
else
{
int * ip = va_arg(args, int *);
*ip = (str - buf);
}
continue;
case 'f': /* Floating point (decimal) */
case 'e': /* Floating point (e) */
case 'E': /* Floating point (E) */
ftoa(sprint_fe, va_arg(args, double), precision, *fmt); /* 浮点转字符串*/
if (!(flags&LEFT))
{
for (j = strnlen(sprint_fe, SZ_NUM_BUF); j<field_width; j++)
*str++= ' ';
}
i = 0;
while(sprint_fe[i]) *str++ = sprint_fe[i++]; /* 主体 */
while (j++ < field_width) *str++ = ' ';
continue;
case '%':
*str++ = '%';
continue;
case 'o':
base = 8;
break;
case 'X':
flags |= LARGE;
case 'x':
base = 16;
break;
case 'd':
case 'i':
flags |= SIGN;
case 'u':
break;
default:
*str++ = '%';
if (*fmt)
*str++ = *fmt;
else
--fmt;
continue;
}
if (qualifier == 'l')
{
num = va_arg(args, unsigned long);
if (flags & SIGN)
num = (signed long) num;
}
else if (qualifier == 'q')
{
num = va_arg(args, unsigned long long);
if (flags & SIGN)
num = (signed long long) num;
}
else if (qualifier == 'Z')
{
num = va_arg(args, size_t);
}
else if (qualifier == 'h')
{
num = (unsigned short) va_arg(args, int);
if (flags & SIGN)
num = (signed short) num;
}
else
{
num = va_arg(args, unsigned int);
if (flags & SIGN)
num = (signed int) num;
}
str = number(str, num, base, field_width, precision, flags);
}
*str = '\0';
return str-buf;
}
int bench_sprintf( char *s, const char *fmt, ... )
{
va_list arg;
va_start( arg, fmt );
int length = bench_vsprintf( s, fmt, arg );
va_end( arg );
return length;
}
int bench_printf(const char *fmt, ... )
{
char s[PRINT_BUF_SIZE];
va_list arg;
va_start( arg, fmt );
int length = bench_vsprintf( s, fmt, arg );
va_end( arg );
for(int i = 0; s[i] != '\0'; i++)
{
putch(s[i]);
}
return length;
}