Skip to content

Commit

Permalink
[one-cmds] Revise one-codegen
Browse files Browse the repository at this point in the history
This commit revises one-codegen.

- Revise the overall logic to make it easy to maintain.
- Rename confusing variables.
- Add missing checks for input validation.

ONE-DCO-1.0-Signed-off-by: seongwoo <[email protected]>
  • Loading branch information
mhs4670go committed Sep 27, 2024
1 parent c59ddc6 commit bfe8ada
Show file tree
Hide file tree
Showing 10 changed files with 382 additions and 180 deletions.
408 changes: 235 additions & 173 deletions compiler/one-cmds/one-codegen

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion compiler/one-cmds/tests/one-codegen_neg_004.test
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ filename="${filename_ext%.*}"

trap_err_onexit()
{
if grep -q "error: 'command' key is missing in the configuration file" "${filename}.log"; then
if grep -q "error: Not found the command for given backend" "${filename}.log"; then
echo "${filename_ext} SUCCESS"
exit 0
fi
Expand Down
2 changes: 1 addition & 1 deletion compiler/one-cmds/tests/one-codegen_neg_005.test
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ filename="${filename_ext%.*}"

trap_err_onexit()
{
if grep -q "error: commands for the backend is missing" "${filename}.log"; then
if grep -q "error: Not found the command for given backend" "${filename}.log"; then
echo "${filename_ext} SUCCESS"
exit 0
fi
Expand Down
1 change: 0 additions & 1 deletion compiler/one-cmds/tests/onecc_066.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ one-codegen=True
target=onecc_066

[one-codegen]
invalid_option=onecc_066
verbose=True
input=onecc_066.circle
output=onecc_066.tvn
4 changes: 2 additions & 2 deletions compiler/one-cmds/tests/onecc_066.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Have invalid options in the [one-codegen]
# Valid option with command schema

: '
This test assumes below directories.
Expand Down Expand Up @@ -107,7 +107,7 @@ onecc -C ${configfile} > ${filename}.log 2>&1
clean_envir

if grep -q "${driver_name} with onecc_066 target" "${outputfile}"; then
if grep -q "HELP MESSAGE!!" "${filename}.log"; then
if ! grep -q "HELP MESSAGE!!" "${filename}.log"; then
echo "${filename_ext} SUCCESS"
exit 0
fi
Expand Down
4 changes: 2 additions & 2 deletions compiler/one-cmds/tests/onecc_neg_028.test
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# use 'backend' and 'backends' option simultaneously
# use 'backend' and 'backends' keys simultaneously

filename_ext="$(basename -- $0)"
filename="${filename_ext%.*}"

trap_err_onexit()
{
if grep -q "option cannot be used simultaneously" "${filename}.log"; then
if grep -q "keys cannot be used simultaneously" "${filename}.log"; then
echo "${filename_ext} SUCCESS"
exit 0
fi
Expand Down
11 changes: 11 additions & 0 deletions compiler/one-cmds/tests/onecc_neg_040.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[onecc]
one-codegen=True

[backend]
target=onecc_neg_040

[one-codegen]
invalid_option=onecc_neg_040
verbose=True
input=onecc_neg_040.circle
output=onecc_neg_040.tvn
2 changes: 2 additions & 0 deletions compiler/one-cmds/tests/onecc_neg_040.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
TARGET=onecc_neg_040
BACKEND=dummy
13 changes: 13 additions & 0 deletions compiler/one-cmds/tests/onecc_neg_040.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from onelib import argumentparse
from onelib.argumentparse import DriverName, NormalOption, TargetOption


def command_schema():
parser = argumentparse.ArgumentParser()
parser.add_argument("dummy-compiler", action=DriverName)
parser.add_argument("--target", action=TargetOption)
parser.add_argument("--verbose", action=NormalOption, dtype=bool)
parser.add_argument("input", action=NormalOption)
parser.add_argument("output", action=NormalOption)

return parser
115 changes: 115 additions & 0 deletions compiler/one-cmds/tests/onecc_neg_040.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#!/bin/bash

# Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Have invalid options in the [one-codegen]

: '
This test assumes below directories.
[one hierarchy]
one
├── backends
│ └── command
│ └── codegen
├── bin
├── doc
├── include
├── lib
├── optimization
├── target
└── test # pwd
'

BACKENDS_ALREADY_EXIST=true
CMD_ALREADY_EXIST=true
DUMMY_ALREADY_EXIST=true
TARGET_ALREADY_EXIST=true

BACKEND_NAME="dummy"

filename_ext="$(basename -- $0)"
filename="${filename_ext%.*}"

driver_name="dummy-compiler"
configfile="onecc_neg_040.cfg"
outputfile="onecc_neg_040.tvn"
targetfile="onecc_neg_040.ini"

clean_envir()
{
rm -rf ../bin/${driver_name}
rm -rf ../target/${targetfile}
rm -rf "../backends/command/${BACKEND_NAME}/codegen.py"
if [ "$TARGET_ALREADY_EXIST" = false ]; then
rm -rf ../target/
fi
if [ "$DUMMY_ALREADY_EXIST" = false ]; then
rm -rf "../backends/command/${BACKEND_NAME}/"
fi
if [ "$CMD_ALREADY_EXIST" = false ]; then
rm -rf ../backends/command/
fi
if [ "$BACKENDS_ALREADY_EXIST" = false ]; then
rm -rf ../backends/
fi
}

trap_err_onexit()
{
if grep -q "Invalid option in \[one-codegen\] section" "${filename}.log"; then
echo "${filename_ext} SUCCESS"
clean_envir
exit 0
fi

echo "${filename_ext} FAILED"
clean_envir
exit 255
}

trap trap_err_onexit ERR

rm -f ${filename}.log
rm -rf ${outputfile}

if [ ! -d "../target/" ]; then
mkdir -p ../target/
TARGET_ALREADY_EXIST=false
fi
if [ ! -d "../backends/" ]; then
mkdir -p ../backends/
BACKENDS_ALREADY_EXIST=false
fi
if [ ! -d "../backends/command/" ]; then
mkdir -p ../backends/command/
CMD_ALREADY_EXIST=false
fi
if [ ! -d "../backends/command/${BACKEND_NAME}/" ]; then
mkdir -p ../backends/command/${BACKEND_NAME}/
DUMMY_ALREADY_EXIST=false
fi

# copy dummy tools to bin folder
cp ${driver_name} ../bin/
cp ${targetfile} ../target/
cp onecc_neg_040.py "../backends/command/${BACKEND_NAME}/codegen.py"

# run test
onecc -C ${configfile} > ${filename}.log 2>&1

echo "${filename_ext} FAILED"
clean_envir
exit 255

0 comments on commit bfe8ada

Please sign in to comment.