- 分享
OJ使用教程(临)
- 2024-9-23 14:56:49 @
USTC OJ使用指南
账号登录
作为助教,首次登录USTC OJ需要使用统一身份认证登录,点击右上角登录按钮,弹出如下界面,选择统一身份认证登录:
由于助教账号未导入系统,所以助教首次登录后会进入注册页面,填写密码后即可登录成功
创建班级
助教创建账号之后,在主题库并没有权限,我们可以选择右上角我的班级,进入页面后点创建班级为自己创建班级:
在创建班级界面必填项填入信息,点击创建按钮即可创建班级:
管理班级
在自己创建的班级下面,点击管理班级,可能需要输入鉴权密码,该密码和注册时设置的密码相同(若账号为批量导入的,则密码为123456),即可管理班级。
在管理班级面板下,点击管理角色->创建角色,为学生创建student角色(若不这么做,则班级下只有一个分组即root),student权限不需要修改,将default和guest角色查看班级的权限关闭。
导入学生
为OJ系统导入用户
对于整个ustc系统,我们可以批量导入用户。这需要向管理员提供包含****学生邮箱,学号的excel表格。管理员联系方式qq:2125873653。批量导入的用户默认密码为123456。
为班级导入用户
批量导入:待开发
邀请码:点击加域申请按钮,按如下方法设置
邀请码填写自己喜欢的信息。
会跳出下面的窗口,将下面的信息粘贴给学生即可
添加题目
在当前班级下的题库,点击创建题目,可以创建一道题目。
注意题目一般用于作业或者考试,所以添加题目后,需要将题目设置为隐藏,设置为隐藏的方法是在编辑选项下勾选隐藏按钮
从主题库导入题目
在主题库打开题目后,点击右侧的复制,能将题目复制到自己的班级下。
添加传统OJ题
若创建的是传统题,则只需要在编辑好题目后,在评测设置右侧上传按.in,.out一组的zip包,将所有测试点打成一个压缩包上传,系统可以自动解压。
若对题目有时间限制或者空间限制上的调整,则在左侧config文件下进行相应的调整,格式参考https://hydro.js.org/docs/user/testdata.html#%E4%BD%BF%E7%94%A8%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6。
添加verilog题
同上,在创建verilog题后对题目进行编辑。编辑好后会进入到评测设置界面。
评测设置略微麻烦,需要如下文件:
输入波形生成函数sim_main.cpp
,生成用于评测的输入波形,格式如下:
// For std::unique_ptr
#include <memory>
// Include common routines
#include <verilated.h>
// Include model header, generated from Verilating "top.v"
#include "Vtop.h"
#include "verilated_vcd_c.h"
// Legacy function required only so linking works on Cygwin and MSVC++
double sc_time_stamp() { return 0; }
int main(int argc, char** argv) {
// Create logs/ directory in case we have traces to put under it
Verilated::mkdir("logs");
// Using unique_ptr is similar to
// "VerilatedContext* contextp = new VerilatedContext" then deleting at end.
const std::unique_ptr<VerilatedContext> contextp{new VerilatedContext};
// Set debug level, 0 is off, 9 is highest presently used
// May be overridden by commandArgs argument parsing
contextp->debug(0);
// Randomization reset policy
// May be overridden by commandArgs argument parsing
contextp->randReset(2);
// Verilator must compute traced signals
contextp->traceEverOn(true);
// Pass arguments so Verilated code can see them, e.g. $value$plusargs
// This needs to be called before you create any model
contextp->commandArgs(argc, argv);
// Construct the Verilated model, from Vtop.h generated from Verilating "top.v".
// Using unique_ptr is similar to "Vtop* top = new Vtop" then deleting at end.
// "TOP" will be the hierarchical name of the module.
const std::unique_ptr<Vtop> top{new Vtop{contextp.get(), "TOP"}};
// Set Vtop's input signals
VerilatedVcdC* tfp = new VerilatedVcdC;
top->trace(tfp, 99); // Trace 99 levels of hierarchy (or see below)
//tfp->dumpvars(1, "t"); // trace 1 level under "t"
tfp->open("wave.vcd");
#define MAX_SIM_TIME 3 // 最大时钟周期
// Simulate until $finish,主要需要修改的地方
while (contextp->time() < MAX_SIM_TIME) {
contextp->timeInc(1); // 1 timeprecision period passes...
//在这个位置添加波形的仿真方法,例如top->po = 1则是生成一个恒为1的输入
//if(contextp->time() == 1) top->clk = 0; else top->clk^=1;则是生成时钟
// Evaluate model
top->eval();
tfp->dump(contextp->time());
}
tfp->close();
// Final model cleanup
top->final();
// Coverage analysis (calling write only after the test is known to pass)
#if VM_COVERAGE
Verilated::mkdir("logs");
contextp->coveragep()->write("logs/coverage.dat");
#endif
// Return good completion status
// Don't use exit() or destructor won't get called
return 0;
}
我们在在这个位置添加波形的仿真方法
处添加仿真的输入
wave.vcd:你在本地跑上述仿真跑出来的正确答案
input.vc:写上下面的内容:
+librescan +libext+.v+.sv+.vh+.svh -y .
compile.sh:写下面的内容:
#!/bin/bash
make clean
echo >> top.v
make
make clean
mv wave.vcd foo
cat foo
Makefile:写上下面的内容:
VERILATOR = /usr/bin/verilator
# Generate C++ in executable form
VERILATOR_FLAGS += -cc -exe
# Generate makefile dependencies (not shown as complicates the Makefile)
# VERILATOR_FLAGS += -MMD
# Optimize
VERILATOR_FLAGS += -x-assign fast
# Warn abount lint issues; may not want this on less solid designs
# VERILATOR_FLAGS += -Wall
# Make waveforms
VERILATOR_FLAGS += --trace
# Check SystemVerilog assertions
VERILATOR_FLAGS += --assert
# Generate coverage analysis
# VERILATOR_FLAGS += --coverage
# Run Verilator in debug mode
#VERILATOR_FLAGS += --debug
# Add this trace to get a backtrace in gdb
#VERILATOR_FLAGS += --gdbbt
VERILATOR_FLAGS += -Wno-CASEOVERLAP
VERILATOR_FLAGS += -Wno-WIDTHEXPAND
# Input files for Verilator
VERILATOR_INPUT = -f input.vc top.v sim_main.cpp
######################################################################
default: run
run:
$(VERILATOR) $(VERILATOR_FLAGS) $(VERILATOR_INPUT)
# To compile, we can either
# 1. Pass --build to Verilator by editing VERILATOR_FLAGS above.
# 2. Or, run the make rules Verilator does:
$(MAKE) -j -C obj_dir -f Vtop.mk
# 3. Or, call a submakefile where we can override the rules ourselves:
# $(MAKE) -j -C obj_dir -f ../Makefile_obj
obj_dir/Vtop +trace
######################################################################
# Other targets
maintainer-copy::
clean mostlyclean distclean maintainer-clean::
-rm -rf obj_dir logs *.log *.dmp *.vpd coverage.dat core
in文件:添加一个空的没有后缀的名字叫in的文件,这是因为评测机需要有输入文件,但实际上我们不需要输入。
最后,我们在左侧将评测设置如下;
创建作业
在一个班级里,我们需要为学生创建作业,我们以****实时可以看到成绩的比赛的形式创建作业。进入比赛界面,点击添加比赛,看到如下界面:
将规则设置为****IOI(实时可以看到成绩的比赛),在题目处添加当前班级内的题目编号如P1,P2等...用逗号隔开。其他选项自行设置。
之后让学生参加这场比赛,即可加入作业。
布置考试
考试方法同作业,创建比赛,但是将赛制改为OI赛制,这样学生无法在中途看到自己的提交结果。