Skip to content

Commit

Permalink
feat(lab5): specialize lab5 grader
Browse files Browse the repository at this point in the history
Signed-off-by: Yiyang Wu <[email protected]>
  • Loading branch information
ToolmanP committed Oct 14, 2024
1 parent 078ec6d commit e432a4f
Show file tree
Hide file tree
Showing 14 changed files with 251 additions and 2 deletions.
1 change: 1 addition & 0 deletions Lab5/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
LAB := 5
TIMEOUT := 120

include $(CURDIR)/../Scripts/lab.mk
8 changes: 8 additions & 0 deletions Lab5/scores-part1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"capture": "All fs tests passed",
"msg": "FSM",
"proposed": 20,
"userland": true
}
]
8 changes: 8 additions & 0 deletions Lab5/scores-part2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"capture": "All fs tests passed",
"msg": "FS_Base Vnode",
"proposed": 15,
"userland": true
}
]
8 changes: 8 additions & 0 deletions Lab5/scores-part3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"capture": "All fs tests passed",
"msg": "FS Server Entry",
"proposed": 15,
"userland": true
}
]
26 changes: 26 additions & 0 deletions Lab5/scores-part4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"capture": "test_open finished",
"msg": "wrapper open & close",
"proposed": 10,
"userland": true
},
{
"capture": "test_content finished",
"msg": "wrapper read & write",
"proposed": 20,
"userland": true
},
{
"capture": "test_lseek finished",
"msg": "wrapper lseek",
"proposed": 10,
"userland": true
},
{
"capture": "test_mmap finished",
"msg": "wrapper mmap",
"proposed": 10,
"userland": true
}
]
56 changes: 56 additions & 0 deletions Scripts/extras/lab5.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
V ?= 0
Q := @

ifeq ($(V), 1)
Q :=
endif

GRADER := $(SCRIPTS)/extras/lab5/grader.sh
BUILDDIR := $(LABDIR)/build
KERNEL_IMG := $(BUILDDIR)/kernel.img
_QEMU := $(SCRIPTS)/qemu_wrapper.sh $(QEMU)
QEMU_GDB_PORT := 1234
QEMU_OPTS := -machine raspi3b -nographic -serial mon:stdio -m size=1G -kernel $(KERNEL_IMG)
CHBUILD := $(SCRIPTS)/chbuild
SERIAL := $(shell tr -dc A-Za-z0-9 </dev/urandom | head -c 13; echo)

export LABROOT LABDIR SCRIPTS LAB TIMEOUT

all: build

defconfig:
$(Q)$(CHBUILD) defconfig

build:
$(Q)test -f $(LABDIR)/.config || $(CHBUILD) defconfig
$(Q)$(CHBUILD) build
$(Q)find $(LABDIR) -path */compile_commands.json \
! -path $(LABDIR)/compile_commands.json -print \
| $(SCRIPTS)/merge_compile_commands.py

clean:
$(Q)$(CHBUILD) clean

distclean:
$(Q)$(CHBUILD) distclean

qemu: build
$(Q)$(_QEMU) $(QEMU_OPTS)

qemu-grade:
$(Q)$(CHBUILD) clean
$(MAKE) build
$(Q)$(_QEMU) $(QEMU_OPTS)

qemu-gdb: build
$(Q)echo "[QEMU] Waiting for GDB Connection"
$(Q)$(_QEMU) -S -gdb tcp::$(QEMU_GDB_PORT) $(QEMU_OPTS)

gdb:
$(Q)$(GDB) --nx -x $(SCRIPTS)/gdb/gdbinit

grade:
$(MAKE) distclean
$(Q)$(GRADER)

.PHONY: qemu qemu-gdb gdb defconfig build clean distclean grade all
14 changes: 14 additions & 0 deletions Scripts/extras/lab5/cmake/cmake-fs_base-full.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
# Licensed under the Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
# http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v2 for more details.

add_library(fs_base STATIC fs_page_cache.c fs_page_fault.c fs_vnode.c
fs_wrapper_ops.c fs_wrapper.c)
target_include_directories(fs_base PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
chcore_copy_all_targets_to_ramdisk()
14 changes: 14 additions & 0 deletions Scripts/extras/lab5/cmake/cmake-fs_base-part1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
# Licensed under the Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
# http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v2 for more details.

add_library(fs_base STATIC fs_page_cache.c fs_page_fault.c fs_wrapper.c.obj
fs_wrapper_ops.c.obj fs_vnode.c.obj)
target_include_directories(fs_base PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
chcore_copy_all_targets_to_ramdisk()
14 changes: 14 additions & 0 deletions Scripts/extras/lab5/cmake/cmake-fs_base-part2-server_entry.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
# Licensed under the Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
# http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v2 for more details.

add_library(fs_base STATIC fs_page_cache.c fs_page_fault.c fs_wrapper.c
fs_wrapper_ops.c.obj fs_vnode.c)
target_include_directories(fs_base PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
chcore_copy_all_targets_to_ramdisk()
14 changes: 14 additions & 0 deletions Scripts/extras/lab5/cmake/cmake-fs_base-part2-vnode.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
# Licensed under the Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
# http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v2 for more details.

add_library(fs_base STATIC fs_page_cache.c fs_page_fault.c fs_wrapper.c.obj
fs_wrapper_ops.c.obj fs_vnode.c)
target_include_directories(fs_base PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
chcore_copy_all_targets_to_ramdisk()
16 changes: 16 additions & 0 deletions Scripts/extras/lab5/cmake/cmake-fsm-full.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
# Licensed under the Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
# http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v2 for more details.

add_executable(fsm.srv device.c fsm.c fsm_client_cap.c mount_disk_fs.c mount_info.c)
add_library(yaml STATIC IMPORTED)
set_target_properties(yaml PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/libs/libyaml.a")
target_link_libraries(fsm.srv PRIVATE yaml)
target_include_directories(fsm.srv PRIVATE .)
chcore_all_force_static_linked()
16 changes: 16 additions & 0 deletions Scripts/extras/lab5/cmake/cmake-fsm-part2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
# Licensed under the Mulan PSL v2.
# You can use this software according to the terms and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
# http://license.coscl.org.cn/MulanPSL2
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
# PURPOSE.
# See the Mulan PSL v2 for more details.

add_executable(fsm.srv device.c fsm.c.obj fsm_client_cap.c.obj mount_disk_fs.c mount_info.c)
add_library(yaml STATIC IMPORTED)
set_target_properties(yaml PROPERTIES IMPORTED_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}/libs/libyaml.a")
target_link_libraries(fsm.srv PRIVATE yaml)
target_include_directories(fsm.srv PRIVATE .)
chcore_all_force_static_linked()
54 changes: 54 additions & 0 deletions Scripts/extras/lab5/grader.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

CMAKE_EXTRA_DIR="${LABROOT}/Scripts/extras/lab5/cmake"
SYSTEM_SERVER_DIR="${LABDIR}/user/system-services/system-servers"
FSM_DIR="${SYSTEM_SERVER_DIR}/fsm"
FS_BASE_DIR="${SYSTEM_SERVER_DIR}/fs_base"

test -f ${LABDIR}/.config && cp ${LABDIR}/.config ${LABDIR}/.config.bak

if [[ -z $LABROOT ]]; then
echo "Please set the LABROOT environment variable to the root directory of your project. (Makefile)"
exit 1
fi

. ${LABROOT}/Scripts/shellenv.sh

cp "${FSM_DIR}/CMakeLists.txt" "${FSM_DIR}/CMakeLists.txt.bak"
cp "${FS_BASE_DIR}/CMakeLists.txt" "${FS_BASE_DIR}/CMakeLists.txt.bak"

info "Grading lab ${LAB} ...(may take ${TIMEOUT} seconds)"
bold "==========================================="
score=0
# Part1 FSM
cp "${CMAKE_EXTRA_DIR}/cmake-fsm-full.txt" "${FSM_DIR}/CMakeLists.txt"
cp "${CMAKE_EXTRA_DIR}/cmake-fs_base-part1.txt" "${FS_BASE_DIR}/CMakeLists.txt"
${SCRIPTS}/capturer.py -f ${LABDIR}/scores-part1.json -t 30 make qemu-grade 2> /dev/null
score=$(($score+$?))
# Part2 VNode
cp "${CMAKE_EXTRA_DIR}/cmake-fsm-part2.txt" "${FSM_DIR}/CMakeLists.txt"
cp "${CMAKE_EXTRA_DIR}/cmake-fs_base-part2-vnode.txt" "${FS_BASE_DIR}/CMakeLists.txt"
${SCRIPTS}/capturer.py -f ${LABDIR}/scores-part2.json -t 30 make qemu-grade 2> /dev/null
score=$(($score+$?))
# Part3 Server Entry
cp "${CMAKE_EXTRA_DIR}/cmake-fsm-part2.txt" "${FSM_DIR}/CMakeLists.txt"
cp "${CMAKE_EXTRA_DIR}/cmake-fs_base-part2-server_entry.txt" "${FS_BASE_DIR}/CMakeLists.txt"
${SCRIPTS}/capturer.py -f ${LABDIR}/scores-part3.json -t 30 make qemu-grade 2> /dev/null
score=$(($score+$?))
# Part4 Ops
mv "${FSM_DIR}/CMakeLists.txt.bak" "${FSM_DIR}/CMakeLists.txt"
mv "${FS_BASE_DIR}/CMakeLists.txt.bak" "${FS_BASE_DIR}/CMakeLists.txt"
${SCRIPTS}/capturer.py -f ${LABDIR}/scores-part4.json -t 30 make qemu-grade 2> /dev/null
score=$(($score+$?))

info "Score: $score/100"
bold "==========================================="

test -f ${LABDIR}/.config.bak && cp ${LABDIR}/.config.bak ${LABDIR}/.config && rm .config.bak
cp "${CMAKE_EXTRA_DIR}/cmake-fsm-part2.txt" "${FSM_DIR}/CMakeLists.txt"

if [[ $score -lt 100 ]]; then
exit $?
else
exit 0
fi
4 changes: 2 additions & 2 deletions Scripts/lab.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ endif

LABDIR := $(LABROOT)/Lab$(LAB)
SCRIPTS := $(LABROOT)/Scripts
GRADER := $(SCRIPTS)/grader.sh
GRADER ?= $(SCRIPTS)/grader.sh

include $(SCRIPTS)/env_generated.mk

Expand All @@ -32,7 +32,7 @@ TIMEOUT ?= 10

ifeq ($(shell test $(LAB) -eq 0; echo $$?),1)
QEMU := $(QEMU-SYS)
ifeq ($(shell test $(LAB) -gt 5; echo $$?),0)
ifeq ($(shell test $(LAB) -gt 4; echo $$?),0)
include $(LABROOT)/Scripts/extras/lab$(LAB).mk
else
include $(LABROOT)/Scripts/kernel.mk
Expand Down

0 comments on commit e432a4f

Please sign in to comment.