Re: [Fuego] Patch for Functional.check_mounts

Kumar T <[email protected]>
Newsgroups dev.linux.lists.fuego
Message-ID <CA+wOOGjGqpA_4yXoXqcSA4FkNhJp6CE5D_7BMZ2we+WRdE7JVQ@mail.gmail.com>
Hi Tim,

         I have restructured the code as per your suggestions. I have taken
one of your patch as reference as created this "check_mounts" test cases
without using C code.  Fixed all the review comments.

        Please find the attached PATCH and other source files.
        Could you please review this patch.

Thanks,
Kumar.




On Tue, 3 Dec 2019 at 18:13, Kumar T <[email protected]> wrote:

> Hi Tim,
>
> Thanks a lot for your time and review comments.
>
> Apologies for the basic mistakes which I have done. I will correct these
> kinds of mistakes from upcoming patches.
>
> > After considering the issue, I think it would be better to structure the
> fs_test.c
> > code as a tool that takes two files and compares them
> > (kind of like diff, but allowing out-of-order lines).
>
> > Instead of hard-coding the filenames, please use 2 filenames that are
> passed
> > on the command line.
>
>    I will structure the fs_test.c code as tool that takes two files as
> command line arguments and compares them.
>    Will work on those review comments.
>
> > This will cause the internal code in Fuego that unpacks the source into
> the
> > build directory to copy the contents of the test's home directory there.
> > The build will then proceed as usual.
>
> > This will allow me to code review the source code for compiled portions
> > of the test, along with the fuego_test.sh, spec.json, and other
> Fuego-specific
> > test materials.
>
> > Please try this out, and let me know if you see any problems.
>
>   I will check and update you on this.
>
> Thanks,
> Kumar.
>
> On Mon, 2 Dec 2019 at 19:19, <[email protected]> wrote:
>
>>
>>
>> > -----Original Message-----
>> > From: [email protected]
>> >
>> > > -----Original Message-----
>> > > From: Kumar T [mailto:[email protected]]
>> > I plan to add a feature to Fuego to support an unpack operation for
>> "local"
>> > files (source files
>> > that are in the test directory - where the fuego_test.sh file
>> resides).  I'd like
>> > to use this test
>> > as a test case for that new feature.  I'll let you know the details of
>> when this
>> > feature is completed.
>>
>>
>> OK - I have added the feature to Fuego, and checked it into the master
>> branch.
>>
>> Now, instead of using the 'tarball' variable to specify the compiled code
>> for a test,
>> you can place the materials to be compiled directly into the test's home
>> directory
>> (e.g. you can put fs_test.c, the Makefile, and the README.md into
>> fuego-core/tests/Functional.check_mounts).
>>
>> Inside the fuego_test.sh, instead of using a 'tarball=' line, put a line
>> like the
>> following at the top of the file:
>> local_source=1
>>
>> This will cause the internal code in Fuego that unpacks the source into
>> the
>> build directory to copy the contents of the test's home directory there.
>> The build will then proceed as usual.
>>
>> This will allow me to code review the source code for compiled portions
>> of the test, along with the fuego_test.sh, spec.json, and other
>> Fuego-specific
>> test materials.
>>
>> Please try this out, and let me know if you see any problems.
>>  -- Tim
>>
>>
0001-check_mounts-PATCH-1-1.patch (text/x-patch, 5.4 KB)
From dd8285cac45305f80a8d4d24c41e8debaa92c3f0 Mon Sep 17 00:00:00 2001
From: Kumar Thangavel <[email protected]>
Date: Thu, 9 Jan 2020 16:57:19 +0530
Subject: [PATCH] <check_mounts>:[PATCH 1/1]

This PATCH added test cases to check the expected mounts
with system mount points. If any mount point is not matched
test would fail. It has save_baseline spec to save the
system mount points as expected mount points.

Signed-off-by: Kumar Thangavel <[email protected]>
---
 tests/Functional.check_mounts/fuego_test.sh | 91 +++++++++++++++------
 tests/Functional.check_mounts/test.yaml     |  5 +-
 2 files changed, 70 insertions(+), 26 deletions(-)

diff --git a/tests/Functional.check_mounts/fuego_test.sh b/tests/Functional.check_mounts/fuego_test.sh
index 609999b..cd6fa62 100755
--- a/tests/Functional.check_mounts/fuego_test.sh
+++ b/tests/Functional.check_mounts/fuego_test.sh
@@ -1,41 +1,86 @@
-tarball=fs-test-1.1.tgz
+# Functional.check_mounts
+#  This test checks to see if the mount points is different from a 
+#  a baseline snapshot taken some time in the past.
+#
+#  The purpose of this test is to do a high-level comparison of the 
+#  mount points of filesystem, to see if anything has changed since
+#  the last baseline snapshot was made.
+#
+# Usage:
+#  preparation:
+#    Create 2 jobs:
+#     $ ftc add-job -b <brd> -t Functional.check_mounts -s default
+#     $ ftc add-job -b <brd> -t Functional.check_mounts -s save_baseline
+#    Save baseline reports
+#      If the filesystem mount points is in a known-good state that reflects "normal"
+#      status for a board,
+#      save the baseline data into a file by running run
+#      the 'save_baseline' job:
+#     $ ftc build-job <brd>.save_baseline.Functional.check_mounts
+#      This will create baseline report files in /fuego-rw/boards/<brd>
+# periodic usage:
+#     Check that the overall reports still match, by running the default job:
+#     $ ftc build-job <board>.default.Functional.check_mounts
+#
 
-function test_build {
-    make
-}
-
-function test_deploy {
+function test_pre_check {
+    # check_mounts dependencies
+    assert_has_program awk
 
-    EXPECTED_FILE=/fuego-rw/boards/$NODE_NAME/expected_mounts.txt
+    export board_rw_dir=$FUEGO_RW/boards/$NODE_NAME
+    export baseline_file=$board_rw_dir/$TESTDIR-baseline-data.txt
 
-    if [ "$TESTSPEC" = "default" ] ; then
+    mkdir -p $board_rw_dir
 
-    	if [ -f "${EXPECTED_FILE}" ] ; then
-      	    put "${EXPECTED_FILE}" $BOARD_TESTDIR/fuego.$TESTDIR/ 
-	else
-            abort_job "Please create file ${EXPECTED_FILE} with the list of expected mounts"
-        fi
+    # check for existence of baseline file
 
-        put fs_test $BOARD_TESTDIR/fuego.$TESTDIR/
+    # but don't check if we're doing the save operation
+    if [ "$TESTSPEC" = "save_baseline" ] ; then
+        return 0
     fi
 
+    if [ ! -f $baseline_file ] ; then
+        echo "Missing baseline results file: $baseline_file1"
+        echo "Maybe try running test with the 'save_baseline' spec?"
+        abort_job "Missing baseline results file"
+    fi
 }
- 
+
 function test_run {
+    echo "Getting mount points"
 
-    DATA_FILE=$LOGDIR/expected_mount_data.txt
+    DATA_FILE=$LOGDIR/mount_points.txt
 
+    # get the mounted points from system
+    cmd "cat /proc/mounts | awk '{print substr($1, 1, length($1))}'" >$DATA_FILE
+    #cat /proc/mounts | awk '{print substr($1, 1, length($1))}' >$DATA_FILE
+    log_this "echo \"Here is the current mounted points :\""
+    log_this "cat $DATA_FILE"
+    echo "--------"
+
+    # if we're doing the "save_baseline" spec, save the data
     if [ "$TESTSPEC" = "save_baseline" ] ; then
-        mount | awk '{print substr($1, 1, length($1))}'>$DATA_FILE
-	cp $DATA_FILE ${EXPECTED_FILE}
-        log_this "echo \"baseline file: ${EXPECTED_FILE} saved\""
+        cp $DATA_FILE $baseline_file
+        log_this "echo \"baseline file: $baseline_file saved\""
+        log_this "echo \"ok 1 compare system mounted points with baseline saved\""
         return 0
-    else
-        report "cd $BOARD_TESTDIR/fuego.$TESTDIR; \
-        ./fs_test"
+    fi
+
+    # check for differences from baseline
+    set +e
+    log_this "echo \"Checking for differences in mount points\""
+    log_this "diff -u $baseline_file $LOGDIR/mount_points.txt"
+    diff_rcode="$?"
+    log_this "echo ------------------------"
+    set -e
+
+    if [ $diff_rcode == "0" ] ; then
+        log_this "echo \"no changes found between current mount points and baseline\""
+	log_this "echo \"ok \""
     fi
 }
 
 function test_processing {
-    log_compare "$TESTDIR" "0" "FAIL" "n"
+    log_compare $TESTDIR 1 "^ok " "p"
 }
+
diff --git a/tests/Functional.check_mounts/test.yaml b/tests/Functional.check_mounts/test.yaml
index beaa67c..b1fc55a 100644
--- a/tests/Functional.check_mounts/test.yaml
+++ b/tests/Functional.check_mounts/test.yaml
@@ -1,8 +1,8 @@
 fuego_package_version: 1
 name: Functional.check_mounts
 description: |
-    Run fs_test, using an 'expected_mounts.txt' file, in order to verify
-    that the mouned filesystems on the target board are as expected.
+    This test checks to see if the mount points is different from a 
+    a baseline snapshot taken some time in the past.
 license: MIT
 author: Kumar Thangavel <[email protected]>
 maintainer: Kumar Thangavel <[email protected]>
@@ -11,5 +11,4 @@ fuego_release: 1
 type: Functional
 tags: ['example']
 data_files:
- - fs-test-1.1.tgz
  - spec.json
-- 
2.17.1
fuego_test.sh (application/x-shellscript, 2.8 KB)
# Functional.check_mounts
#  This test checks to see if the mount points is different from a 
#  a baseline snapshot taken some time in the past.
#
#  The purpose of this test is to do a high-level comparison of the 
#  mount points of filesystem, to see if anything has changed since
#  the last baseline snapshot was made.
#
# Usage:
#  preparation:
#    Create 2 jobs:
#     $ ftc add-job -b <brd> -t Functional.check_mounts -s default
#     $ ftc add-job -b <brd> -t Functional.check_mounts -s save_baseline
#    Save baseline reports
#      If the filesystem mount points is in a known-good state that reflects "normal"
#      status for a board,
#      save the baseline data into a file by running run
#      the 'save_baseline' job:
#     $ ftc build-job <brd>.save_baseline.Functional.check_mounts
#      This will create baseline report files in /fuego-rw/boards/<brd>
# periodic usage:
#     Check that the overall reports still match, by running the default job:
#     $ ftc build-job <board>.default.Functional.check_mounts
#

function test_pre_check {
    # check_mounts dependencies
    assert_has_program awk

    export board_rw_dir=$FUEGO_RW/boards/$NODE_NAME
    export baseline_file=$board_rw_dir/$TESTDIR-baseline-data.txt

    mkdir -p $board_rw_dir

    # check for existence of baseline file

    # but don't check if we're doing the save operation
    if [ "$TESTSPEC" = "save_baseline" ] ; then
        return 0
    fi

    if [ ! -f $baseline_file ] ; then
        echo "Missing baseline results file: $baseline_file1"
        echo "Maybe try running test with the 'save_baseline' spec?"
        abort_job "Missing baseline results file"
    fi
}

function test_run {
    echo "Getting mount points"

    DATA_FILE=$LOGDIR/mount_points.txt

    # get the mounted points from system
    cmd "cat /proc/mounts | awk '{print substr($1, 1, length($1))}'" >$DATA_FILE
    #cat /proc/mounts | awk '{print substr($1, 1, length($1))}' >$DATA_FILE
    log_this "echo \"Here is the current mounted points :\""
    log_this "cat $DATA_FILE"
    echo "--------"

    # if we're doing the "save_baseline" spec, save the data
    if [ "$TESTSPEC" = "save_baseline" ] ; then
        cp $DATA_FILE $baseline_file
        log_this "echo \"baseline file: $baseline_file saved\""
        log_this "echo \"ok 1 compare system mounted points with baseline saved\""
        return 0
    fi

    # check for differences from baseline
    set +e
    log_this "echo \"Checking for differences in mount points\""
    log_this "diff -u $baseline_file $LOGDIR/mount_points.txt"
    diff_rcode="$?"
    log_this "echo ------------------------"
    set -e

    if [ $diff_rcode == "0" ] ; then
        log_this "echo \"no changes found between current mount points and baseline\""
	log_this "echo \"ok \""
    fi
}

function test_processing {
    log_compare $TESTDIR 1 "^ok " "p"
}
test.yaml (application/x-yaml, 391 B) - not displayed
spec.json (application/json, 153 B) - not displayed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.