Skip to content

Commit

Permalink
Added empty define extraction condition to sed expressions, added exp…
Browse files Browse the repository at this point in the history
…lanations and fixed test_statfs success logs
  • Loading branch information
EngineersBox committed Oct 22, 2023
1 parent 22ca52f commit a9ca8c8
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
40 changes: 40 additions & 0 deletions vvsfs/vvsfs_tests/generate_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,25 @@ echo " - VVSFS_HEADER = $VVSFS_HEADER"
echo " - CC = $CC"
echo

# Sed lines explanation:
# 1. Keeps lines prefixed with "#define"
# 2. Removes empty definition line "#define VVSFS_H"
# keeping normal definitions like "#define true 1"
# 3. Extract name of define and replace entire
# expression of "#define <NAME> <VALUE>" to
# "<NAME>"
# Note that we use the -E and -dM flags with the
# compiler to perform the following:
# -E: Do a pre-process pass only
# -dM: Dump macro expressions to stdout (note that
# without -E, this is interpreted instead as
# -fdump-rtl-mach, used to dump compiler state
# after the machine dependent reorganisation
# pass)
DEFINES_NAMES=$(
sed -nr '{
/^#define/!d
/^#define[ \t]*[^ \t]*[ \t]*$/d
s/^#define[ \t](VVSFS[^ \t(]*)([ \t]\(?).*/\1/p
}' <($CC -E -dM $VVSFS_HEADER)
)
Expand All @@ -28,6 +44,29 @@ EXPANSION_CODE=$(
| awk '{print "EXPAND(\""$0"\","$0");"}'
)

# Code explanation:
#
# The format_specifier macro uses the builtin
# compile time _Generic(x) to extract the type
# name from the expression, then pattern matches
# this against the type expressions to convert
# the appropriate type to a printf format
# specifier. This allows for fully type-safe
# printing of resolved values (expressions).
#
# The EXPAND macro uses the builtin compile time
# __typeof__ expression to fully qualify the
# definition of the temporary _a according to the
# type of the expression passed in (this is
# different from _Generic(x) which is a pattern
# matching expansion and token consumer). Using
# this (now type safe) declaration of _a, we can
# print its value according to the appropriate
# format specifier resolved with the previously
# explained macro format_specifier along with the
# name, into a bash variable delcaration format
# matching <NAME>=<VALUE>.

# Note the use of "|| true" here, since "read"
# returns an exit code of 1, we need to ensure
# that it doesnt trigger any wrapping scripts
Expand Down Expand Up @@ -66,6 +105,7 @@ EOF
TMP=$(mktemp)
echo "$EXPANSION_CODE" | gcc -o $TMP -xc -
chmod a+x $TMP

echo "#!/bin/bash" > $ENV_FILE_NAME
$TMP >> $ENV_FILE_NAME
chmod a+x $ENV_FILE_NAME
Expand Down
4 changes: 2 additions & 2 deletions vvsfs/vvsfs_tests/test_statfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ assert_eq "$(stat -f -c %c testdir)" "$VVSFS_MAX_INODE_ENTRIES" "total inode cou
check_log_success "Total inode count correct"
# Free inodes %d
assert_eq "$(stat -f -c %d testdir)" "3994" "free inode count incorrect"
check_log_success "Free inode count incorrect"
check_log_success "Free inode count correct"

./remount.sh

Expand Down Expand Up @@ -69,5 +69,5 @@ assert_eq "$(stat -f -c %c testdir)" "$VVSFS_MAX_INODE_ENTRIES" "total inode cou
check_log_success "Total inode count correct after remount"
# Free inodes %d
assert_eq "$(stat -f -c %d testdir)" "3994" "free inode count incorrect after remount"
check_log_success "Free inode count incorrect after remount"
check_log_success "Free inode count correct after remount"

0 comments on commit a9ca8c8

Please sign in to comment.