def L_AtomicFile_Stream_0023(target, legato, init_atomicFile):
    """Purpose: Verify that le_atomFile_TryOpenStream can successfully.

    acquire a file lock to the target file

    Initial condition:
        1. Test app is unsandboxed

    Verification:
        This test case will mark as "failed" when
            1. The second process who calls le_atomFile_OpenStream
               does not block after the first
               process of the test app held the file lock

    This script will
        1. Transfer a file to the target
        1. Make and install the test app
        2. Run the test app
        3. Check  the second process does block after the first process
        successfully acquired the lock == 0:

    :param target: fixture to communicate with the target
    :param legato: fixture to call useful functions regarding legato
    :param app_leg: fixture regarding to build, install and remove app
    :param init_atomicFile: fixture to initialize and clean up environment
    """
    test_app_name = "atomTryOpenStream"
    test_app_proc_name = "atomTryOpenStreamProc"
    hw_file_path = os.path.join(TEST_TOOLS, "testFile.txt")
    test_file_path = "/home/root/testFile.txt"
    test_description = "acquireFlock"
    swilog.debug(init_atomicFile)

    # Wait for the occurrence of the specified message in the target's log
    # Pre:
    # Param: $1 - message to be expected from the log; $2 - wait time period
    # Post: return 0 when the message has been found; 1 otherwise

    files.scp([hw_file_path], test_file_path, target.target_ip)
    legato.clear_target_log()

    legato.runProc(test_app_name, test_app_proc_name, test_file_path,
                   test_description)

    assert legato.wait_for_log_msg("first process is holding a file lock",
                                   5) is True, ("[FAILED] the first process "
                                                "can't acquire a file lock "
                                                "when it calls "
                                                "le_atomFile_TryOpenStream")

    assert (legato.wait_for_log_msg("second process is holding a file lock",
                                    120) is
            True), ("[FAILED] "
                    "le_atomFile_TryOpenStream"
                    " can't successfully "
                    "acquire a file lock to the"
                    " target file")
Beispiel #2
0
def L_AtomicFile_Stream_0032(target, legato, init_atomicFile):
    """Purpose: Verify that le_atomFile_CancelStream cancels.

    all changes and close the file
    pointer returned by le_atomFile_OpenStream,
    le_atomFile_TryOpenStream,
    le_atomFile_CreateStream and le_atomFile_TryCreateStream
    with a read file lock

    Initial condition:
        1. Test app is unsandboxed

    Verification:
        This test case will mark as "failed" when
            1. File's contents being modified

    This script will
       1. Make and install the test app
       2. Run the test app
       3. Check  file's contents remain unchanged == 0:
       4. Repeat above for different test scenarios

    :param target: fixture to communicate with the target
    :param legato: fixture to call useful functions regarding legato
    :param app_leg: fixture regarding to build, install and remove app
    :param init_atomicFile: fixture to initialize and clean up environment

    """
    test_app_name = "atomCancelStream"
    test_app_proc_name = "atomCancelStreamProc"
    hw_file_path = os.path.join(TEST_TOOLS, "testFile.txt")
    test_file_path = init_atomicFile
    test_descriptions = [
        "openStreamReadFlockOK",
        "tryOpenStreamReadFlockOK",
        "createStreamReadFlockOK",
        "tryCreateStreamReadFlockOK",
    ]

    ref_file_path = "/home/root/refFile.txt"
    files.scp([hw_file_path], ref_file_path, target.target_ip)

    for td in test_descriptions:
        files.scp([hw_file_path], test_file_path, target.target_ip)
        legato.clear_target_log()
        legato.runProc(test_app_name, test_app_proc_name, test_file_path, td)
        assert legato.wait_for_log_msg("le_atomFile_CancelStream is called",
                                       20) is True
        target.run("diff %s %s" % (test_file_path, ref_file_path))

    swilog.info("[PASSED] le_atomFile_CancelStream cancels"
                " all changes and closes the file pointer) "
                "for le_atomFile_OpenStream(, "
                "le_atomFile_TryOpenStream(, le_atomFile_CreateStream( and "
                "le_atomFile_TryCreateStream( with a read file lock")
Beispiel #3
0
def L_AtomicFile_Operation_0031(target, legato, init_atomicFile):
    """Purpose: Verify that le_atomFile_Cancel cancels all changes.

    and closes the file descriptor for
    le_atomFile_Open(, le_atomFile_TryOpen(,le_atomFile_Create(
    and le_atomFile_TryCreate( with a write file lock

    Initial condition:
        1. test app is unsandboxed

    Verification:
       This test case will mark as "failed" when
            1. le_atomFile_Cancel commits all changes

    This script will

        1. Make and install the test app
        2. Run the test app
        3. Check latest changes weren't committed after \
           le_atomFile_Cancel is called == 0:
        4. Repeat above for different test scenarios

    :param target: fixture to communicate with the target
    :param legato: fixture to call useful functions regarding legato
    :param app_leg: fixture regarding to build, install and remove app
    :param init_atomicFile: fixture to initialize and clean up environment
    """
    test_app_name = "atomCancel"
    test_app_proc_name = "atomCancelProc"
    hw_file_path = os.path.join(TEST_TOOLS, "testFile.txt")
    test_file_path = init_atomicFile
    test_descriptions = [
        "openWrtFlockOK",
        "tryOpenWrtFlockOK",
        "createWrtFlockOK",
        "tryCreateWrtFlockOK",
    ]

    ref_file_path = "/home/root/refFile.txt"
    files.scp([hw_file_path], ref_file_path, target.target_ip)

    for td in test_descriptions:
        files.scp([hw_file_path], test_file_path, target.target_ip)
        legato.clear_target_log()
        legato.runProc(test_app_name, test_app_proc_name, test_file_path, td)
        assert legato.wait_for_log_msg("le_atomFile_Cancel is called", 20) is True
        target.run("diff %s %s" % (test_file_path, ref_file_path))

    swilog.info(
        "\n[PASSED] le_atomFile_Cancel"
        " cancels all changes and closes the file descriptor) for "
        "le_atomFile_Open(, le_atomFile_TryOpen(, le_atomFile_Create("
        " and le_atomFile_TryCreate( with a write file lock"
    )
Beispiel #4
0
def L_AtomicFile_Operation_0040(target, legato, init_atomicFile):
    """Purpose: Verify that le_atomFile_TryDelete returns LE_WOULD_BLOCK.

    file is already locked == 0

    Initial condition:
        1. Test app is unsandboxed

    Verification:
        This test case will mark as "failed" when
            1. le_atomFile_TryDelete doesn't return LE_WOULD_BLOCK
            2. Target file is removed

    This script will
        1. Make and install the test app
        2. Run the test app
        3. Check  "le_atomFile_TryDelete returns LE_WOULD_BLOCK ..."
           can be captured from the target's log == 0:
        4. Check  target file isn't deleted == 0:

    :param target: fixture to communicate with the target
    :param legato: fixture to call useful functions regarding legato
    :param app_leg: fixture regarding to build, install and remove app
    :param init_atomicFile: fixture to initialize and clean up environment
    """
    test_app_name = "atomTryDelete"
    test_app_proc_name = "atomTryDeleteProc"
    hw_file_path = os.path.join(TEST_TOOLS, "testFile.txt")
    target_log_cmd = "/sbin/logread"
    test_file_path = init_atomicFile
    test_description = "wouldBlock"

    files.scp([hw_file_path], test_file_path, target.target_ip)
    legato.clear_target_log()
    legato.runProc(test_app_name, test_app_proc_name, test_file_path,
                   test_description)

    cmd = r"%s | grep \"\[PASSED\]\|\[FAILED\]\"" % target_log_cmd
    if legato.ssh_to_target(cmd) != 0:
        assert 0, ("[FAILED] unable to get the test app's"
                   " output message form the target's syslog")

    if legato.ssh_to_target(r"%s | grep \"\[PASSED\]\"" % target_log_cmd) != 0:
        assert 0, "test returned [FAILED]"

    if target.run(" [ -e %s ]" % (test_file_path), withexitstatus=1)[0] == 0:
        swilog.info("[PASSED] le_atomFile_TryDelete won't delete"
                    " the file which it has an associated file lock")
    else:
        assert 0, ("[FAILED] le_atomFile_TryDelete deleted the "
                   "file which it has an associated file lock")
Beispiel #5
0
def L_AtomicFile_Operation_0008(target, legato, init_atomicFile):
    """Purpose: Verify that le_atomFile_Create returns LE_DUPLICATE.

    if the target file already existed and
    LE_FLOCK_FAIL_IF_EXIST is specified in createMode

    Initial condition:
        1. Test app is unsandboxed

    Verification:
        This test case will mark as "failed" when
            1. le_atomFile_Create doesn't return LE_DUPLICATE

    This script will
        1. Transfer a file to the target
        2. Make and install the test app
        3. Run the test app
        4. Check if "le_atomFile_Create returns LE_DUPLICATE ..." \
           can be captured from the target's log

    :param target: fixture to communicate with the target
    :param legato: fixture to call useful functions regarding legato
    :param app_leg: fixture regarding to build, install and remove app
    :param init_atomicFile: fixture to initialize and clean up environment
    """
    test_app_name = "atomCreate"
    test_app_proc_name = "atomCreateProc"
    hw_file_path = os.path.join(TEST_TOOLS, "testFile.txt")
    target_log_cmd = "/sbin/logread"
    test_file_path = init_atomicFile
    test_description = "duplicate"

    files.scp([hw_file_path], test_file_path, target.target_ip)

    legato.clear_target_log()

    rsp = legato.runProc(test_app_name, test_app_proc_name, test_file_path,
                         test_description)

    time.sleep(5)
    cmd = target_log_cmd
    rsp = target.run(cmd)
    swilog.info(rsp)
    assert "PASSED" in rsp or "FAILED" in rsp, ("[FAILED] unable to get the "
                                                "test app's output message "
                                                "form the target's syslog")
    assert "PASSED" in rsp, "test returned [FAILED]"
def L_AtomicFile_Stream_0024(target, legato, init_atomicFile):
    """Purpose: Verify that resultPtr of le_atomFile_TryCreateStream returns.

    LE_DUPLICATE  the target file already == 0: existed and
    LE_FLOCK_FAIL_IF_EXIST is specified in createMode

    Initial condition:
        1. Test app is unsandboxed

    Verification:
        This test case will mark as "failed" when
            1. le_atomFile_TryCreateStream doesn't return LE_DUPLICATE

    This script will
        1. Transfer a file to the target
        2. Make and install the test app
        3. Run the test app
        4. Check  "resultPtr of le_atomFile_TryCreateStream returns
           LE_DUPLICATE ..." can be captured from the target's log == 0:

    :param target: fixture to communicate with the target
    :param legato: fixture to call useful functions regarding legato
    :param app_leg: fixture regarding to build, install and remove app
    :param init_atomicFile: fixture to initialize and clean up environment
    """
    test_app_name = "atomTryCreateStream"
    test_app_proc_name = "atomTryCreateStreamProc"
    hw_file_path = os.path.join(TEST_TOOLS, "testFile.txt")
    target_log_cmd = "/sbin/logread"
    test_file_path = init_atomicFile
    test_description = "duplicate"

    files.scp([hw_file_path], test_file_path, target.target_ip)
    legato.clear_target_log()
    legato.runProc(test_app_name, test_app_proc_name, test_file_path,
                   test_description)

    cmd = r"%s | grep \"\[PASSED\]\|\[FAILED\]\"" % target_log_cmd
    if legato.ssh_to_target(cmd) != 0:
        assert 0, ("[FAILED] unable to get the test app's "
                   "output message form the target's syslog")

    cmd = r"%s | grep \"\[PASSED\]\"" % target_log_cmd
    if legato.ssh_to_target(cmd) != 0:
        assert 0, "test returned [FAILED]"
Beispiel #7
0
def L_AtomicFile_Operation_0003(target, legato, init_atomicFile):
    """Purpose: Verify that le_atomFile_Open returns the file descriptor.

    when successfully opens the file

    Initial condition:
        1. test app is unsandboxed

    Verification:
        This test case will mark as "failed" when
            1. le_atomFile_Open doesn't return a file descriptor

    This script will
        1. Make and install the test app
        2. Run the test app
        3. Check  "le_atomFile_Open returns a file descriptor ..." \
           can be captured from the target's log == 0:

    :param target: fixture to communicate with the target
    :param legato: fixture to call useful functions regarding legato
    :param app_leg: fixture regarding to build, install and remove app
    :param init_atomicFile: fixture to setup and cleanup environment
    """
    test_app_name = "atomOpen"
    test_app_proc_name = "atomOpenProc"
    hw_file_path = os.path.join(TEST_TOOLS, "testFile.txt")
    target_log_cmd = "/sbin/logread"
    test_file_path = init_atomicFile
    test_description = "fd"

    files.scp([hw_file_path], test_file_path, target.target_ip)

    legato.clear_target_log()

    rsp = legato.runProc(test_app_name, test_app_proc_name, test_file_path,
                         test_description)

    time.sleep(5)
    cmd = target_log_cmd
    rsp = target.run(cmd)
    swilog.info(rsp)
    assert "PASSED" in rsp or "FAILED" in rsp, ("[FAILED] unable to get the "
                                                "test app's output message "
                                                "form the target's syslog")
Beispiel #8
0
def L_AtomicFile_Operation_0019(target, legato, init_atomicFile):
    """Purpose: Verify that le_atomFile_TryOpen returns LE_WOULD_BLOCK.

    there is already == 0: an incompatible lock on the file

    Initial condition:
        1. Test app is unsandboxed

    Verification:
        This test case will mark as "failed" when
            1. le_atomFile_TryOpen doesn't return LE_WOULD_BLOCK

    This script will
        1. Make and install the test app
        2. Run the test app
        3. Check  "le_atomFile_TryOpen returns LE_WOULD_BLOCK ..."
           can be captured from the target's log == 0:

    :param target: fixture to communicate with the target
    :param legato: fixture to call useful functions regarding legato
    :param app_leg: fixture regarding to build, install and remove app
    :param init_atomicFile: fixture to initialize and clean up environment
    """
    test_app_name = "atomTryOpen"
    test_app_proc_name = "atomTryOpenProc"
    hw_file_path = os.path.join(TEST_TOOLS, "testFile.txt")
    target_log_cmd = "/sbin/logread"
    test_file_path = init_atomicFile
    test_description = "wouldBlock"

    files.scp([hw_file_path], test_file_path, target.target_ip)

    legato.clear_target_log()

    legato.runProc(test_app_name, test_app_proc_name, test_file_path,
                   test_description)

    cmd = r"%s | grep \"\[PASSED\]\|\[FAILED\]\"" % target_log_cmd
    if legato.ssh_to_target(cmd) != 0:
        assert 0, ("[FAILED] unable to get the test app's output message"
                   " form the target's syslog")

    if legato.ssh_to_target(r"%s | grep \"\[PASSED\]\"" % target_log_cmd) != 0:
        assert 0, "test returned [FAILED]"
Beispiel #9
0
def L_AtomicFile_Stream_0029(target, legato, init_atomicFile):
    r"""Purpose: Verify that le_atomFile_CloseStream commits all changes.

    closes the file pointer
    and returns LE_OK for le_atomFile_CloseStreamStream(,
    le_atomFile_TryOpenStream(, le_atomFile_CreateStream(
    and le_atomFile_TryCreateStream( with a write file lock

    Initial condition:
        1. Test app is unsandboxed

    Verification:
        This test case will mark as "failed" when
            1. le_atomFile_CloseStream doesn't commits all changes
            2. le_atomFile_CloseStream doesn't return LE_OK

    This script will
        1. Make and install the test app
        2. Run the test app
        3. Check  \"le_atomFile_CloseStream returns LE_OK ...\" \
           can be captured from the target's log == 0:
        4. Check  latest changes were committed after \
           le_atomFile_CloseStream is called == 0:
        5. Repeat above for different test scenarios

    :param target: fixture to communicate with the target
    :param legato: fixture to call useful functions regarding legato
    :param app_leg: fixture regarding to build, install and remove app
    :param init_atomicFile: fixture to initialize and clean up environment
    """
    test_app_name = "atomCloseStream"
    test_app_proc_name = "atomCloseStreamProc"
    hw_file_path = os.path.join(TEST_TOOLS, "testFile.txt")
    test_file_path = init_atomicFile
    test_descriptions = [
        "openStreamWrtFlockOK",
        "tryOpenStreamWrtFlockOK",
        "createStreamWrtFlockOK",
        "tryCreateStreamWrtFlockOK",
    ]

    for td in test_descriptions:
        files.scp([hw_file_path], test_file_path, target.target_ip)
        legato.clear_target_log()
        legato.runProc(test_app_name, test_app_proc_name, test_file_path, td)
        assert legato.wait_for_log_msg("le_atomFile_CloseStream is called",
                                       20) is True

        cmd = r" cat %s | grep -q \"String Foo\"" % (test_file_path)
        if legato.ssh_to_target(cmd) != 0:
            assert 0, ("[FAILED] le_atomFile_CloseStream "
                       "doesn't commit all changes for test scenario of %s" %
                       td)

        exp_log = "le_atomFile_CloseStream returns LE_OK"
        if legato.find_in_target_log(exp_log) is False:
            assert 0, ("[FAILED] le_atomFile_CloseStream "
                       "doesn't return LE_OK for test scenario of %s" % td)

        swilog.info("[PASSED] le_atomFile_CloseStream commits "
                    "all changes, closes the file pointer "
                    "and returns LE_OK for "
                    "le_atomFile_OpenStream(, le_atomFile_TryOpenStream(,"
                    " le_atomFile_CreateStream( "
                    "and le_atomFile_TryCreateStream( "
                    "with a write file lock")
Beispiel #10
0
def L_AtomicFile_Operation_0030(target, legato, init_atomicFile):
    """Purpose: Verify that le_atomFile_Close commits all changes.

    closes the file descriptor
    and returns LE_OK for le_atomFile_Open(,
    le_atomFile_TryOpen(, le_atomFile_Create(
    and le_atomFile_TryCreate( with a read file lock

    Initial condition:
        1. Test app is unsandboxed

    Verification:
        This test case will mark as "failed" when
            1. File's contents being modified
            2. le_atomFile_Close doesn't return LE_OK

    This script will
       1. Make and install the test app
       2. Run the test app
       3. Check  "le_atomFile_Close returns LE_OK ..." \
       can be captured from the target's log == 0:
       4. Check  file's contents remain unchanged == 0:
       5. Repeat above for different test scenarios

    :param target: fixture to communicate with the target
    :param legato: fixture to call useful functions regarding legato
    :param app_leg: fixture regarding to build, install and remove app
    :param init_atomicFile: fixture to initialize and clean up environment
    """
    test_app_name = "atomClose"
    test_app_proc_name = "atomCloseProc"
    hw_file_path = os.path.join(TEST_TOOLS, "testFile.txt")
    test_file_path = init_atomicFile
    test_descriptions = [
        "openReadFlockOK",
        "tryOpenReadFlockOK",
        "createReadFlockOK",
        "tryCreateReadFlockOK",
    ]

    ref_file_path = "/home/root/refFile.txt"
    files.scp([hw_file_path], ref_file_path, target.target_ip)

    for td in test_descriptions:
        files.scp([hw_file_path], test_file_path, target.target_ip)
        legato.clear_target_log()
        legato.runProc(test_app_name, test_app_proc_name, test_file_path, td)

        assert legato.wait_for_log_msg("le_atomFile_Close is called",
                                       20) is True

        target.run("diff %s %s" % (test_file_path, ref_file_path))

        exp_log = "le_atomFile_Close returns LE_OK"
        if legato.find_in_target_log(exp_log) is False:
            assert 0, ("[FAILED] le_atomFile_Close doesn't return "
                       "LE_OK for test scenario of %s" % td)

    swilog.info("[PASSED] le_atomFile_Close commits all changes,"
                " closes the file descriptor and returns LE_OK for "
                "le_atomFile_Open(, le_atomFile_TryOpen(,"
                " le_atomFile_Create( and le_atomFile_TryCreate( "
                "with a read file lock")