diff options
author | Ingo Huerner <ingo_huerner@mentor.com> | 2016-03-30 13:01:32 +0200 |
---|---|---|
committer | Ingo Huerner <ingo_huerner@mentor.com> | 2016-03-30 13:01:32 +0200 |
commit | fe4b73dcc282932ae3ebb8805e0b617a0016dc9a (patch) | |
tree | 0481770b26d5824114f2fe74c5b2b00f05d18013 | |
parent | 6b208bfc268890360fcbd5cede70da5d2f9fb459 (diff) | |
download | persistence-client-library-fe4b73dcc282932ae3ebb8805e0b617a0016dc9a.tar.gz |
Removed obsolete tests
-rw-r--r-- | test/Makefile.am | 11 | ||||
-rwxr-xr-x | test/pers_pfs_test_starter.sh | 45 | ||||
-rwxr-xr-x | test/persistence-pfs-test-start.service | 12 | ||||
-rw-r--r-- | test/persistence_client_library_benchmark.c | 649 | ||||
-rw-r--r-- | test/persistence_pfs_test.c | 687 |
5 files changed, 1 insertions, 1403 deletions
diff --git a/test/Makefile.am b/test/Makefile.am index 51f61cf..8a3fa87 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -9,25 +9,16 @@ AM_CFLAGS = $(DEPS_CFLAGS) $(CHECK_CFLAGS) endif noinst_PROGRAMS = persistence_client_library_test \ - persistence_client_library_dbus_test \ - persistence_client_library_benchmark \ - persistence_pfs_test + persistence_client_library_dbus_test persistence_client_library_dbus_test_SOURCES = persistence_client_library_dbus_test.c persistence_client_library_dbus_test_LDADD = $(DEPS_LIBS) \ $(top_builddir)/src/libpersistence_client_library.la -persistence_client_library_benchmark_SOURCES = persistence_client_library_benchmark.c -persistence_client_library_benchmark_LDADD = $(DEPS_LIBS) \ - $(top_builddir)/src/libpersistence_client_library.la - persistence_client_library_test_SOURCES = persistence_client_library_test.c persistence_client_library_test_LDADD = $(DEPS_LIBS) $(CHECK_LIBS) \ $(top_builddir)/src/libpersistence_client_library.la -persistence_pfs_test_SOURCES = persistence_pfs_test.c -persistence_pfs_test_LDADD = $(DEPS_LIBS) \ - $(top_builddir)/src/libpersistence_client_library.la TESTS=persistence_client_library_test diff --git a/test/pers_pfs_test_starter.sh b/test/pers_pfs_test_starter.sh deleted file mode 100755 index 418e2fe..0000000 --- a/test/pers_pfs_test_starter.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -# Use this script to start the persistence power fail save test after system restart - -# HOW TO USE -# to start this script on startup, copy the systemd service file persistence-pfs-test-start.service to /lib/systemd/system/ -# Create also a link from /lib/systemd/system/multi-user.target.wants -# to the persistence-pfs-test-start.service in /lib/systemd/system/ - -echo "Starting persistence power fail save test" - -check_process() { - echo "$ts: checking $1" - [ "$1" = "" ] && return 0 - [ `pgrep -n $1` ] && return 1 || return 0 -} - -#!!!!!!!!!!!!dlt daemon has to run before starting test -# check if already running, otherwise error -# timestamp -ts=`date +%T` - -echo "$ts: begin checking apps needed..." -check_process "dlt-daemon" -if [ $? == 0 ] -then - echo "$ts: not running, starting ..." - dlt-daemon & -else - echo "$ts: already running..." -fi - -export LD_LIBRARY_PATH='/usr/lib/' - -if [ $# != 0 ] -then - numLoops=$1 -else - numLoops=10000000 -fi - -/usr/bin/persistence_pfs_test "-l $numLoops" "-s/dev/ttyUSB0" - - -echo "End of persistence power fail save test"
\ No newline at end of file diff --git a/test/persistence-pfs-test-start.service b/test/persistence-pfs-test-start.service deleted file mode 100755 index ed6446a..0000000 --- a/test/persistence-pfs-test-start.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description=Persistence Power Fails Save test starter script -After=dbus.service - -[Service] -Type=simple -ExecStart=/usr/bin/pers_pfs_test_starter.sh -StandardOutput=tty -StandardError=tty - -[Install] -WantedBy=multi-user.target
\ No newline at end of file diff --git a/test/persistence_client_library_benchmark.c b/test/persistence_client_library_benchmark.c deleted file mode 100644 index a9b4a98..0000000 --- a/test/persistence_client_library_benchmark.c +++ /dev/null @@ -1,649 +0,0 @@ -/****************************************************************************** - * Project Persistency - * (c) copyright 2014 - * Company XS Embedded GmbH - *****************************************************************************/ -/****************************************************************************** - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed - * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -******************************************************************************/ - /** - * @file persistence_client_library_benchmark.c - * @ingroup Persistence client library benchmark - * @author Ingo Huerner - * @brief Benchmark of persistence client library - * @see - */ - -#include "../include/persistence_client_library_key.h" -#include "../include/persistence_client_library_file.h" -#include "../include/persistence_client_library_error_def.h" - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> /* atoi */ - -#include <dlt.h> -#include <dlt_common.h> - -#include <sys/time.h> -#include <sys/resource.h> -#include <pthread.h> - - -#define SECONDS2NANO 1000000000L -#define NANO2MIL 1000000L -#define MIL2SEC 1000L - -#define BUFFER_SIZE 2048 - -// define for the used clock: "CLOCK_MONOTONIC" or "CLOCK_REALTIME" -#define CLOCK_ID CLOCK_MONOTONIC - - -const char* gAppName = "lt-persistence_client_library_benchmark"; - - -char sysTimeBuffer[BUFFER_SIZE]; - - - -inline long long getNsDuration(struct timespec* start, struct timespec* end) -{ - return ((end->tv_sec * SECONDS2NANO) + end->tv_nsec) - ((start->tv_sec * SECONDS2NANO) + start->tv_nsec); -} - -inline double getMsDuration(struct timespec* start, struct timespec* end) -{ - return (double)((end->tv_sec * SECONDS2NANO) + end->tv_nsec) - ((start->tv_sec * SECONDS2NANO) + start->tv_nsec)/NANO2MIL; -} - - - -void init_benchmark(int numLoops) -{ - int i = 0; - long long durationInit = 0; - long long durationDeInit = 0; - struct timespec initStart, initEnd; - struct timespec deInitStart, deInitEnd; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; - - printf("\nTest i n i t / d e i n i t performance: %d times\n", numLoops); - - // init - clock_gettime(CLOCK_ID, &initStart); - (void)pclInitLibrary(gAppName , shutdownReg); - clock_gettime(CLOCK_ID, &initEnd); - durationInit += getNsDuration(&initStart, &initEnd); - - // deinit - clock_gettime(CLOCK_ID, &deInitStart); - pclDeinitLibrary(); - clock_gettime(CLOCK_ID, &deInitEnd); - durationDeInit += getNsDuration(&deInitStart, &deInitEnd); - - printf(" Init (single) => %f ms \n", (double)((double)durationInit/NANO2MIL)); - printf(" Deinit (single) => %f ms \n", (double)((double)durationDeInit/NANO2MIL)); - - durationInit = 0; - durationDeInit = 0; - - - clock_gettime(CLOCK_ID, &initStart); - (void)pclInitLibrary(gAppName , shutdownReg); - clock_gettime(CLOCK_ID, &initEnd); - durationInit += getNsDuration(&initStart, &initEnd); - - // deinit - clock_gettime(CLOCK_ID, &deInitStart); - pclDeinitLibrary(); - clock_gettime(CLOCK_ID, &deInitEnd); - durationDeInit += getNsDuration(&deInitStart, &deInitEnd); - - printf(" Init (single) => %f ms \n", (double)((double)durationInit/NANO2MIL)); - printf(" Deinit (single) => %f ms \n", (double)((double)durationDeInit/NANO2MIL)); - - durationInit = 0; - durationDeInit = 0; - - for(i=0; i<numLoops; i++) - { - // init - clock_gettime(CLOCK_ID, &initStart); - (void)pclInitLibrary(gAppName , shutdownReg); - clock_gettime(CLOCK_ID, &initEnd); - durationInit += getNsDuration(&initStart, &initEnd); - - // deinit - clock_gettime(CLOCK_ID, &deInitStart); - (void)pclDeinitLibrary(); - clock_gettime(CLOCK_ID, &deInitEnd); - durationDeInit += getNsDuration(&deInitStart, &deInitEnd); - } - - printf(" Init => %f ms \n", (double)((double)durationInit/NANO2MIL/numLoops)); - printf(" Deinit => %f ms \n", (double)((double)durationDeInit/NANO2MIL/numLoops)); - -} - - - -void read_benchmark(int numLoops) -{ - int ret = 0, i = 0; - long long duration = 0; - struct timespec readStart, readEnd; - char key[128] = { 0 }; - unsigned char buffer[BUFFER_SIZE] = {0}; - - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; - - (void)pclInitLibrary(gAppName , shutdownReg); - - - printf("\nTest r e a d performance: %d times\n", numLoops); - - clock_gettime(CLOCK_ID, &readStart); - ret = pclKeyReadData(PCL_LDBID_LOCAL, "pos/last_position_w_bench", 1, 2, buffer, BUFFER_SIZE); - clock_gettime(CLOCK_ID, &readEnd); - duration += getNsDuration(&readStart, &readEnd); - printf(" INITIAL read 1 \"pos/last_position_w_bench\" => %f ms for [%d Kilobytes item]\n", (double)((double)duration/NANO2MIL), ret/1024); - - - duration = 0; - memset(buffer, 0, BUFFER_SIZE); - for(i=0; i<numLoops; i++) - { - snprintf(key, 128, "pos/last_position_w_bench%d",i); - clock_gettime(CLOCK_ID, &readStart); - ret = pclKeyReadData(PCL_LDBID_LOCAL, key, 1, 2, buffer, BUFFER_SIZE); - clock_gettime(CLOCK_ID, &readEnd); - - duration += getNsDuration(&readStart, &readEnd); - } - - (void)pclDeinitLibrary(); - - printf(" Further read \"pos/last_position_w_bench\" => %f ms for [%d Kilobytes item]\n", (double)((double)duration/NANO2MIL/numLoops), ret/1024); -} - - - -void write_benchmark(int numLoops) -{ - int ret = 0, i = 0; - long long duration = 0; - long long overallDuration = 0; - - struct timespec writeStart, writeEnd; - char key[128] = { 0 }; - - //(void)pclInitLibrary(gAppName , shutdownReg); - - printf("\nTest w r i t e c a c h e d performance: %d times\n", numLoops); - - clock_gettime(CLOCK_ID, &writeStart); - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "pos/last_position_w_bench", 1, 2, (unsigned char*)sysTimeBuffer, 1024); - clock_gettime(CLOCK_ID, &writeEnd); - duration = getNsDuration(&writeStart, &writeEnd); - printf("Initial Write => %f ms [%d Kilobytes]\n", (double)((double)duration/NANO2MIL), ret/1024); - - overallDuration += duration; - duration = 0; - - for(i=0; i<numLoops; i++) - { - snprintf(key, 128, "pos/last_position_w_bench%d",i); - - clock_gettime(CLOCK_ID, &writeStart); - //ret = pclKeyWriteData(PCL_LDBID_LOCAL, "pos/last_position_w_bench", 1, 2, (unsigned char*)sysTimeBuffer, strlen(sysTimeBuffer)); - ret = pclKeyWriteData(PCL_LDBID_LOCAL, key, 1, 2, (unsigned char*)sysTimeBuffer, 1024); - clock_gettime(CLOCK_ID, &writeEnd); - - duration += getNsDuration(&writeStart, &writeEnd); - } - printf("Further Writes => %f ms for [%d Kilobytes item]\n", (double)((double)duration/NANO2MIL)/numLoops, ret/1024); - - overallDuration += duration; - duration = 0; - - printf("\nTest w r i t e b a c k performance: %d times\n", numLoops); - clock_gettime(CLOCK_ID, &writeStart); - (void)pclDeinitLibrary(); - clock_gettime(CLOCK_ID, &writeEnd); - duration += getNsDuration(&writeStart, &writeEnd); - - overallDuration += duration; - - printf("Writeback for all Writes => %f ms for [%d Megabytes]\n", (double)((double)duration/NANO2MIL), (numLoops * ret) / 1048576); - - printf("Overall duration for write cached and writeback benchmark => %f ms for [%d bytes]\n", (double)((double)overallDuration/NANO2MIL), 2 * numLoops * ret); -} - - - -void handle_benchmark(int numLoops) -{ - int hdl = 0, hdl2 = 0, hdl3 = 0, hdl4 = 0, ret = 0, i = 0; - long long duration = 0; - struct timespec openStart, openEnd; - unsigned char buffer[BUFFER_SIZE] = {0}; - - printf("\nTest h a n d l e performance: %d times\n", numLoops); - - duration = 0; - for(i=0; i<1; i++) - { - clock_gettime(CLOCK_ID, &openStart); - hdl = pclKeyHandleOpen(PCL_LDBID_LOCAL, "handlePos/last_position_ro_bench", 1, 2); - clock_gettime(CLOCK_ID, &openEnd); - - //pclKeyHandleClose(hdl); - - duration += getNsDuration(&openStart, &openEnd); - } - printf(" Open 1 => %f ms\n", (double)((double)duration/NANO2MIL)); - - duration = 0; - for(i=0; i<1; i++) - { - clock_gettime(CLOCK_ID, &openStart); - hdl2 = pclKeyHandleOpen(PCL_LDBID_LOCAL, "handlePos/last_position_ro_bench2", 1, 2); - clock_gettime(CLOCK_ID, &openEnd); - - //pclKeyHandleClose(hdl2); - - duration += getNsDuration(&openStart, &openEnd); - } - printf(" Open 2 => %f ms\n", (double)((double)duration/NANO2MIL)); - - duration = 0; - for(i=0; i<numLoops; i++) - { - clock_gettime(CLOCK_ID, &openStart); - ret = pclKeyHandleReadData(hdl, buffer, BUFFER_SIZE); - //printf("pclKeyHandleReadData retval: %d \n ", ret); - clock_gettime(CLOCK_ID, &openEnd); - - duration += getNsDuration(&openStart, &openEnd); - } - printf(" Read 1 => %f ms [%d bytes]\n", (double)((double)duration/NANO2MIL)/numLoops, ret); -#if 0 - printf(" Buffer [handlePos/last_position_ro_bench] => %d :\n %s \n\n", ret, buffer); -#endif - - - - duration = 0; - for(i=0; i<numLoops; i++) - { - clock_gettime(CLOCK_ID, &openStart); - ret = pclKeyHandleReadData(hdl2, buffer, BUFFER_SIZE); - clock_gettime(CLOCK_ID, &openEnd); - - duration += getNsDuration(&openStart, &openEnd); - } - printf(" Read 2 => %f ms [%d bytes]\n", (double)((double)duration/NANO2MIL)/numLoops, ret); -#if 0 - printf(" Buffer [handlePos/last_position_ro_bench2] => %d :\n %s \n\n", ret, buffer); -#endif - - - - - clock_gettime(CLOCK_ID, &openStart); - hdl3 = pclKeyHandleOpen(PCL_LDBID_LOCAL, "handlePos/last_position_w_bench", 1, 2); - clock_gettime(CLOCK_ID, &openEnd); - duration = getNsDuration(&openStart, &openEnd); - printf(" Open 3 => %f ms\n", (double)((double)duration/NANO2MIL)); - - - clock_gettime(CLOCK_ID, &openStart); - hdl4 = pclKeyHandleOpen(PCL_LDBID_LOCAL, "handlePos/last_position_w_bench2", 1, 2); - clock_gettime(CLOCK_ID, &openEnd); - duration = getNsDuration(&openStart, &openEnd); - printf(" Open 4 => %f ms\n", (double)((double)duration/NANO2MIL)); - - - pclKeyHandleClose(hdl); - pclKeyHandleClose(hdl2); - pclKeyHandleClose(hdl3); - pclKeyHandleClose(hdl4); -} - - -void* do_something(void* dataPtr) -{ - int i = 0; - int value = *((int*)dataPtr); - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; - - // init library - (void)pclInitLibrary(gAppName , shutdownReg); - - for(i=0; i < 5000; i++) - { - switch(value) - { - case 1: - (void)pclKeyWriteData(0x84, "links/last_link2", 2, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data")); - case 2: - (void)pclKeyWriteData(0x84, "links/last_link3", 3, 2, (unsigned char*)"Test notify shared data", strlen("Test notify shared data")); - case 3: - (void)pclKeyWriteData(0x84, "links/last_link4", 4, 1, (unsigned char*)"Test notify shared data", strlen("Test notify shared data")); - break; - default: - printf("Nothing!\n;"); - break; - } - } - - // deinit library - pclDeinitLibrary(); - - return NULL; -} - - -void pcl_init_simple() -{ - long long duration = 0; - - struct timespec start, end; - printf("\n*** Measure i n i t duration\n"); - - clock_gettime(CLOCK_ID, &start); - - // - // initialize the persistence client library - // ------------------------------------------------- - (void)pclInitLibrary(gAppName , PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL); - - - clock_gettime(CLOCK_ID, &end); - duration = getNsDuration(&start, &end); - - printf("*** Init duration => %f ms\n", (double)((double)duration/NANO2MIL)); -} - - -void pcl_read_data_simple() -{ - int ret = 0; - long long duration = 0; - unsigned char buffer[BUFFER_SIZE] = {0}; - - struct timespec start, end; - printf("\n*** Measure r e a d duration\n"); - - clock_gettime(CLOCK_ID, &start); - - // - // read data "pos/last_position_w_bench" - // ------------------------------------------------- - ret = pclKeyReadData(PCL_LDBID_LOCAL, "pos/last_position_w_bench", 1, 2, buffer, BUFFER_SIZE); - - clock_gettime(CLOCK_ID, &end); - duration = getNsDuration(&start, &end); - - if(ret < 0) - { - printf("pcl_read_data_simple => FAILED: %d\n", ret); - } - printf("*** Read duration \"bench\" => %f ms\n", (double)((double)duration/NANO2MIL)); - - - clock_gettime(CLOCK_ID, &start); - - // - // R E A D data "pos/last_position_w_bench" - // ------------------------------------------------- - ret = pclKeyReadData(PCL_LDBID_LOCAL, "pos/last_position_w_bench", 1, 2, buffer, BUFFER_SIZE); - - clock_gettime(CLOCK_ID, &end); - duration = getNsDuration(&start, &end); - - if(ret < 0) - { - printf("pcl_read_data_simple => FAILED: %d\n", ret); - } - printf("*** Read duration \"bench\" => %f ms\n", (double)((double)duration/NANO2MIL)); - - - clock_gettime(CLOCK_ID, &start); - - // - // R E A D data "pos/last_position_w_bench2" - // ------------------------------------------------- - ret = pclKeyReadData(PCL_LDBID_LOCAL, "pos/last_position_w_bench2", 1, 2, buffer, BUFFER_SIZE); - - clock_gettime(CLOCK_ID, &end); - duration = getNsDuration(&start, &end); - - if(ret < 0) - { - printf("pcl_read_data_simple => FAILED: %d\n", ret); - } - printf("*** Read duration \"bench2\" => %f ms\n", (double)((double)duration/NANO2MIL)); - - - clock_gettime(CLOCK_ID, &start); - - - // - // R E A D data "pos/last_position_w_bench" - // ------------------------------------------------- - ret = pclKeyReadData(PCL_LDBID_LOCAL, "pos/last_position_w_bench2", 1, 2, buffer, BUFFER_SIZE); - - clock_gettime(CLOCK_ID, &end); - duration = getNsDuration(&start, &end); - - if(ret < 0) - { - printf("pcl_read_data_simple => FAILED: %d\n", ret); - } - printf("*** Read duration \"bench2\" => %f ms\n", (double)((double)duration/NANO2MIL)); -} - - -void pcl_write_data_simple() -{ - int ret = 0; - long long duration = 0; - unsigned char buffer[BUFFER_SIZE] = {0}; - struct timespec start, end; - - memset(buffer, 0xAA55AA55, BUFFER_SIZE); - - printf("\n*** Measure w r i t e duration\n"); - - clock_gettime(CLOCK_ID, &start); - - // - // W R I T E data "pos/last_position_w_bench" - // ------------------------------------------------- - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "pos/last_position_w_bench", 1, 2, buffer, BUFFER_SIZE); - - clock_gettime(CLOCK_ID, &end); - duration = getNsDuration(&start, &end); - - if(ret < 0) - { - printf("pcl_write_data_simple => FAILED: %d\n", ret); - } - printf("*** Write duration \"bench\" => %f ms\n", (double)((double)duration/NANO2MIL)); - - - - clock_gettime(CLOCK_ID, &start); - - // - // W R I T E data "pos/last_position_w_bench2" - // ------------------------------------------------- - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "pos/last_position_w_bench2", 1, 2, buffer, BUFFER_SIZE); - clock_gettime(CLOCK_ID, &end); - duration = getNsDuration(&start, &end); - - if(ret < 0) - { - printf("pcl_write_data_simple 2 => FAILED: %d\n", ret); - } - - printf("*** Write duration \"bench2\" => %f ms\n", (double)((double)duration/NANO2MIL)); - - clock_gettime(CLOCK_ID, &start); - - // - // W R I T E data "pos/last_position_w_bench2" - // ------------------------------------------------- - ret = pclKeyWriteData(PCL_LDBID_LOCAL, "pos/last_position_w_bench2", 1, 2, buffer, BUFFER_SIZE); - clock_gettime(CLOCK_ID, &end); - duration = getNsDuration(&start, &end); - - - if(ret < 0) - { - printf("pcl_write_data_simple 2 => FAILED: %d\n", ret); - } - printf("*** Write duration \"bench2\" => %f ms\n", (double)((double)duration/NANO2MIL)); -} - - -void pcl_deinit_data_simple() -{ - long long durationDeinit = 0; - struct timespec deinitStart, deinitEnd; - - printf("\n*** Measure d e i n i t duration\n"); - - // init - clock_gettime(CLOCK_ID, &deinitStart); - - // - // uninitialize the persistence client library - // ------------------------------------------------- - (void)pclDeinitLibrary(); - - clock_gettime(CLOCK_ID, &deinitEnd); - durationDeinit = getNsDuration(&deinitStart, &deinitEnd); - - printf("*** Deinit duration => %f ms\n", (double)((double)durationDeinit/NANO2MIL)); -} - - -int main(int argc, char *argv[]) -{ - int ret = 0; - -#if 1 - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; - int numLoops = 1024, // number of default loops - doSimpleBench = 0; - long long resolution = 0; - - struct timespec clockRes; -#else - - int toThread1 = 0, toThread2 = 0, toThread3 = 0; - int* retval1, retval2, retval3; - - pthread_t thread1, thread2, thread3; - -#endif - - - - int opt; - - while ((opt = getopt(argc, argv, "sl:")) != -1) - { - switch (opt) - { - case 's': - doSimpleBench = 1; - break; - case 'l': - numLoops = atoi(optarg); - break; - } - } - - printf("Number of loops: %d\n", numLoops); - - - snprintf(sysTimeBuffer, BUFFER_SIZE, "zu5CXT2WbxCBqnUk0Y4N52H5PRGgVRbNhoY64sZQkRrRw8b6rpBA23Cuf4kxw5PMyo7aX3zdGACf9Z96A5O5MNimlOmmhu6EHDfSVNkA7NLlPX97eh9SOIXiJqQYr85F9eQdGDkbZ9HANfGxekptxeH04EOP2jukxUqKnh2nj33x7TtmMnjfqXFWg0RZ3cRHX1kAQxxr2hUo8uJvNwgooXicXp5L4OWLxIBEkG3yGESQ4dFsy5uoBrZDi78EV7l9dqc7ahA4b8g0TcfYEfiynyRcMPEvKwq4Lvn8T8X001DLu3ig8QAQlzVDF6LTfvvs7hrMCwVKwvtjZBE9UrJ2X8nijX5Ncy8wQ9BkzFI9vqhTt2NOtGCZ808iWPMvamRi1acEPxJI8kIRN8ArIRUidPMTDCWKA97Ffz70zJt5YDaXLNgodKC6dgA5zc99ZwjyRTvXePMQofsQuXLuxFYcamOxtXrRsafjA8CC9Kiu9jOS2tdyYQnoV9oDjJlsvfPqg667oBaGe9b9iyHfqWM42xHVoYj7YERvUiliOB0KYEFM7el8AWc2YnEHq5i0jKhoYHdKll7qqEgoJdvYkczExQ2W85AX8jyFW5XVCeWUTQSYkTnipLI9D27jXw2lYGhh3rlILiM1SFBTYCGflXNfaTsHVAjjda4xpEd6t7JM5E96KkLBBdFWbb2H3wB4qJPgbu2al3X8SUAN4hQ50cUFr1yAFfoGSVYghMShqN5VNUo4s6xXo2FC0jYmeiHQd4dYXUCA31XdruG2f8CPA07ifMveiQl7yEqp4rmHUqzIA5D6SV3IqfYs0Vw8FgBmJZKo9a4JnZjzwlmqa5illZd74vZD0D5iJd4X7gBs3mokEMKN1gMHVIiVQ348sFQuyly2ZKLNCGAglRQAfvHTQSiJiNT7CUJt9OHpUbPyVyaN2gd8LN3b3EAwbLGTS21cI6kSsDcleg9iCmP7VMVhc2Aqu76nKAjDaB7JeRjTSeJ302UwaXWYecN24LNiJKBHXU9q"); - - - /// debug log and trace (DLT) setup - DLT_REGISTER_APP("PCLb","tests the persistence client library"); - - printf("\n\n===============================\n"); - printf(" PCL benchmark ==> %s\n", (doSimpleBench == 1) ? "simple" : "full"); - printf("================================\n\n"); - - clock_getres(CLOCK_ID, &clockRes); - resolution = ((clockRes.tv_sec * SECONDS2NANO) + clockRes.tv_nsec); - printf("Clock resolution => %f ms\n\n", (double)((double)resolution/NANO2MIL)); - - if(doSimpleBench == 1) - { - pcl_init_simple(); - - pcl_read_data_simple(); - - pcl_write_data_simple(); - - pcl_deinit_data_simple(); - - printf("\n\n"); - } - else - { -#if 1 - (void)pclInitLibrary(gAppName , shutdownReg); - - //handle_benchmark(numLoops); - - init_benchmark(numLoops); - - read_benchmark(numLoops); - - //pcldeinit is done inside write_benchmark - write_benchmark(numLoops); - - -#else - - toThread1 = 1; - - ret = pthread_create(&thread1, NULL, do_something, &toThread1); - pthread_setschedprio(thread1, sched_get_priority_max(SCHED_OTHER)); - - toThread2 = 2; - ret = pthread_create(&thread2, NULL, do_something, &toThread2); - pthread_setschedprio(thread2, sched_get_priority_max(SCHED_OTHER)); - - toThread3 = 3; - ret = pthread_create(&thread3, NULL, do_something, &toThread3); - pthread_setschedprio(thread3, sched_get_priority_max(SCHED_OTHER)); - - - // wait until the dbus mainloop has ended - pthread_join(thread1, (void**)&retval1); - // wait until the dbus mainloop has ended - pthread_join(thread2, (void**)&retval2); - // wait until the dbus mainloop has ended - pthread_join(thread3, (void**)&retval3); -#endif - } - - // unregister debug log and trace - DLT_UNREGISTER_APP(); - - dlt_free(); - - return ret; -} - diff --git a/test/persistence_pfs_test.c b/test/persistence_pfs_test.c deleted file mode 100644 index 68f1f6a..0000000 --- a/test/persistence_pfs_test.c +++ /dev/null @@ -1,687 +0,0 @@ -/****************************************************************************** - * Project Persistency - * (c) copyright 2012 - * Company XS Embedded GmbH - *****************************************************************************/ -/****************************************************************************** - * This Source Code Form is subject to the terms of the - * Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed - * with this file, You can obtain one at http://mozilla.org/MPL/2.0/. -******************************************************************************/ - /** - * @file persistence_pfs_test.c - * @ingroup Persistence client library test - * @author Ingo Huerner - * @brief Persistence Power Fail Safe Test - * For this test a computer controlled lab power supply will be used. - * The persistence_pfs_test application sends a command to the power supply - * using the serial console to switch power off for a couple of seconds to - * reboot of the system and simulate unexpected power cut in order to proof - * power fail save of persistence. - * - * @attention To run the test the following things need to do to setup the target: - * There is a script to start this test binary. - * In otder to start this script on startup, copy the systemd service file "persistenc-pfs-test-start.service" - * to /lib/systemd/system/. - * Create also a link from /lib/systemd/system/multi-user.target.wants - * to the persistence-pfs-test-start.service in /lib/systemd/system/ - * - * @see - */ - -#include <stdio.h> -#include <string.h> -#include <fcntl.h> -#include <unistd.h> -#include <errno.h> -#include <stdlib.h> -#include <pthread.h> - -#include <dlt.h> -#include <dlt_common.h> - -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/mount.h> - -#include "../include/persistence_client_library.h" -#include "../include/persistence_client_library_key.h" -#include "../include/persistence_client_library_file.h" - - -#define LC_CNT_START 36 -#define WR_CNT_START 43 -#define BASE_STRING_END 31 - - -DLT_DECLARE_CONTEXT(gPFSDLTContext); - -static const char* gOrigPostfix = "ORIG"; -static const char* gBackupPostfix = "BACK"; - -static int gLifecycleCounter = 0; - -static const char* gTestInProgressFlag = "/Data/mnt-c/persistence_pfst_test_in_progress"; - -static const char* gDefaultKeyValueResName[] = -{ - "keyValue_Resource_00", - "keyValue_Resource_01", - "keyValue_Resource_02", - "keyValue_Resource_03", - "keyValue_Resource_04", - "keyValue_Resource_05", - "keyValue_Resource_06", - "keyValue_Resource_07", - "keyValue_Resource_08", - "keyValue_Resource_09", - "keyValue_Resource_10", - "keyValue_Resource_11", - "keyValue_Resource_12", - "keyValue_Resource_13", - "keyValue_Resource_14", - "keyValue_Resource_15", - "keyValue_Resource_16", - "keyValue_Resource_17", - "keyValue_Resource_18", - "keyValue_Resource_19", -}; - -static const char* gDefaultKeyValueTestData[] = -{ - "keyValue pair cache Zero - %s : 000000 000000", - "keyValue pair cache One - %s : 000000 000000", - "keyValue pair cache Two - %s : 000000 000000", - "keyValue pair cache Three - %s : 000000 000000", - "keyValue pair cache Four - %s : 000000 000000", - "keyValue pair cache Five - %s : 000000 000000", - "keyValue pair wt Six - %s : 000000 000000", - "keyValue pair wt Seven - %s : 000000 000000", - "keyValue pair wt eight - %s : 000000 000000", - "keyValue pair wt nine - %s : 000000 000000", - "keyValue pair wt ten - %s : 000000 000000", - "keyValue pair cache eleven - %s : 000000 000000", - "keyValue pair cache twelve - %s : 000000 000000", - "keyValue pair cache thirteen - %s : 000000 000000", - "keyValue pair cache fourteen - %s : 000000 000000", - "keyValue pair cache fifteen - %s : 000000 000000", - "keyValue pair wt sixteen - %s : 000000 000000", - "keyValue pair wt Seventeen - %s : 000000 000000", - "keyValue pair wt eighteen - %s : 000000 000000", - "keyValue pair wt nineteen - %s : 000000 000000", -}; - - - -static const char* gDefaultFileAPITestData[] = -{ - "file API cache One : 000000 000000", - "file API cache Two : 000000 000000", - "file API cache Three : 000000 000000", - "file API cache Four : 000000 000000", - "file API wt One : 000000 000000", - "file API wt Two : 000000 000000", - "file API wt Three : 000000 000000", - "file API wt Four : 000000 000000" -}; - -static const char* gDefaultFileResNames[] = -{ - "file API_Resource_01", - "file API_Resource_02", - "file API_Resource_03", - "file API_Resource_04", - "file API_Resource_05", - "file API_Resource_06", - "file API_Resource_07", - "file API_Resource_08" -}; - - -// extdern declaration - -extern void pcl_test_send_shutdown_command(); - -// forward declaration - -/// verify written data form previous lifefycle -void verify_data_key_value(); -void verify_data_file(); - - - -/// write data until power off occurs -void write_data_key_value(int numLoops, int counter); -void write_data_file(int numLoops); -int mount_persistence(const char* deviceName); -void unmount_persistence(); - - - -/// setup initial test data -int setup_test_data(const char* postfix) -{ - int i = 0, ret = 0; - char databuffer[64] = {0}; - - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; - - pclInitLibrary("pfs_test", shutdownReg); // register to persistence client library - - // key/value data - for(i=0; i < (int)sizeof(gDefaultKeyValueTestData) / (int)sizeof(char*); i++) - { - memset(databuffer, 0, 64); - snprintf(databuffer, 64, gDefaultKeyValueTestData[i], postfix); - printf(" setup_test_data - [%.2d] => %s\n", i, databuffer); - ret = pclKeyWriteData(PCL_LDBID_LOCAL, gDefaultKeyValueResName[i], 1, 1, (unsigned char*)databuffer, strlen(databuffer)); - if(ret < 0) - { - printf("setup_test_data => failed to write data: %d\n", ret ); - //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("write key/value - failed to write data"), DLT_INT(ret)); - } - } - -#if 0 - // file data - for(i=0; i<sizeof(gDefaultFileAPITestData) / sizeof(char*); i++) - { - printf(" file - data[%d] => %s\n", i, gDefaultFileAPITestData[i]); - } -#endif - - pclDeinitLibrary(); // unregister from persistence client library - sync(); - return 1; -} - - - -void verify_test_setup() -{ - int i = 0, ret = 0; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; - - char buffer[64] = {0}; - - pclInitLibrary("pfs_test", shutdownReg); // register to persistence client library - - for(i=0; i< (int)sizeof(gDefaultKeyValueTestData) / (int)sizeof(char*); i++) - { - ret = pclKeyReadData(PCL_LDBID_LOCAL, gDefaultKeyValueResName[i], 1, 1, (unsigned char*)buffer, 64); - if(ret < 0) - { - printf("verify_test_setup - key/value - pclKeyReadData FAILED: %s => \"%s\"\n", gDefaultKeyValueResName[i], buffer); - } - - printf("verify_test_setup: [%.2d] => %s\n", i, buffer); - - memset(buffer, 0, 64); - } - - pclDeinitLibrary(); // unregister from persistence client library -} - - - -/// after this function has been called the system reboots -void send_snmp_shutdown_cmd() -{ - // command to power off the power supply - const char data[] = { "snmpset -v1 -c public 134.86.58.225 iso.3.6.1.4.1.1909.22.1.1.1.5.1 i 1" }; - - if(system(data) == -1) - { - printf("Failed to execute command: %s\n", data); - } -} - - - -int update_test_progress_flag(const char* filename, int *counter) -{ - int fd = -1, rval = 0; - - if(access(filename, F_OK) == 0) - { - fd = open(filename, O_RDWR); // file exists, update content - if(fd != -1) - { - int size = 0; - char buffer[12] = {0}; - if((size = read(fd, buffer, 12)) != -1) - { - rval = atoi(buffer); - *counter = rval; - snprintf(buffer, 12, "%d", *counter + 1); - - lseek(fd, 0, SEEK_SET); - if((size = write(fd, buffer, strlen(buffer))) == -1) - { - printf(" Failed to write to file: %s » %s\n", filename, strerror(errno)); - } - } - else - { - printf(" Failed to write to file: %s » %s\n", filename, strerror(errno)); - rval = -1; - } - } - else - { - rval = -1; - } - } - else - { - fd = open(filename, O_CREAT|O_RDWR|O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH); - if(fd != -1) - { - int size = 0; - char buffer[12] = {0}; - snprintf(buffer, 12, "%d", 1); - if((size = write(fd, buffer, strlen(buffer))) == -1) - { - printf(" Failed to write to file: %s » %s\n", filename, strerror(errno)); - rval = -1; - } - *counter = 1; - } - else - { - rval = -1; - } - } - syncfs(fd); - close(fd); - return rval; -} - - - -void update_test_data(char* buffer, int lc_counter, int write_counter) -{ - int i = 0; - char lc_cnt_buff[7] = {0}; - char wr_cnt_buff[7] = {0}; - - snprintf(lc_cnt_buff, 7, "%.6d", lc_counter); - snprintf(wr_cnt_buff, 7, "%.6d", write_counter); - - for(i=0; i<6; i++) - { - buffer[LC_CNT_START+i] = lc_cnt_buff[i]; - buffer[WR_CNT_START+i] = wr_cnt_buff[i]; - } -} - - - -int get_lifecycle_count(char* buf) -{ - return atoi(&buf[LC_CNT_START]); -} - -int get_write_count(char* buf) -{ - return atoi(&buf[WR_CNT_START]); -} - -int main(int argc, char *argv[]) -{ - int rVal = EXIT_SUCCESS; - unsigned int shutdownReg = PCL_SHUTDOWN_TYPE_FAST | PCL_SHUTDOWN_TYPE_NORMAL; - - printf("------------------\n"); - printf("P F S - Test start\n"); - printf("------------------\n"); - - /// debug log and trace (DLT) setup - //DLT_REGISTER_APP("PFS","power fail safe test"); - - //DLT_REGISTER_CONTEXT(gPFSDLTContext,"PFS","Context for PCL PFS test logging"); - - -#if 0 - // mount persistence partitions - if(-1 != mount_persistence("/dev/sdb") ) - { -#endif - - int numLoops = 1000000, opt = 0; - - while ((opt = getopt(argc, argv, "l:s:")) != -1) - { - switch (opt) - { - case 'l': - numLoops = atoi(optarg); - break; - } - } - - - - if(update_test_progress_flag(gTestInProgressFlag, &gLifecycleCounter) == 0) - { - printf("PFS test - first lifecycle, setup test data\n"); - //DLT_LOG(gPFSDLTContext, DLT_LOG_INFO, DLT_STRING("PFS test - first lifecycle, setup test data")); - - printf("--- setup data --- \n"); - setup_test_data(gBackupPostfix); - setup_test_data(gOrigPostfix); - - printf("--- verify data setup --- \n"); - verify_test_setup(); - } - - printf("PFS test - Lifecycle counter: %d - number of test loops: %d\n", gLifecycleCounter, numLoops); - /* - DLT_LOG(gPFSDLTContext, DLT_LOG_INFO, DLT_STRING("PFS test - Lifecycle counter:"), DLT_INT(gLifecycleCounter), - DLT_STRING("- number of write loops:"), DLT_INT(numLoops)); - */ - pclInitLibrary("pfs_test", shutdownReg); // register to persistence client library - - // verify the data form previous lifecycle - printf("--- Verify Data ---!!\n"); - verify_data_key_value(); - //verify_data_file(); - - // write data - printf("--- Write Data!! ---\n"); - write_data_key_value(numLoops, gLifecycleCounter); // on odd lifecycle numbers, corrupt db data, otherwise corrupt db header - //write_data_file(numLoops); - - - printf("Deinit library\n"); - pclDeinitLibrary(); // unregister from persistence client library - - -#if 0 - unmount_persistence(); - - } - else - { - //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("PFS test - failed to mount pers partition:"), DLT_INT(gLifecycleCounter) ); - printf("Mount Failed\n"); - rVal = EXIT_FAILURE; - } -#endif - - printf("End of PFS app\n"); - - // unregister debug log and trace - //DLT_UNREGISTER_APP(); - - //dlt_free(); - - printf("Wait until shutdown thread has finished\n"); - - return rVal; -} - - - -void verify_data_key_value() -{ - int i=0, ret = 0; - char buffer[64] = {0}; - - // read data from previous lifecycle - key/value - for(i=0; i< (int)sizeof(gDefaultKeyValueTestData) / (int)sizeof(char*); i++) - { - memset(buffer, 0, 64); - ret = pclKeyReadData(PCL_LDBID_LOCAL, gDefaultKeyValueResName[i], 1, 1, (unsigned char*)buffer, 64); - if(ret < 0) - { - //DLT_LOG(gPFSDLTContext, DLT_LOG_WARN, DLT_STRING("verify - key/value - => failed to read data"), DLT_INT(ret), DLT_STRING(buffer)); - printf("verify - key/value - pclKeyReadData FAILED: %s => \"%s\"\n", gDefaultKeyValueResName[i], buffer); - } - else - { - int lc_count = get_lifecycle_count(buffer); - - // first verify base string - if(0 == strncmp(gDefaultKeyValueTestData[i], buffer, BASE_STRING_END) ) - { - char extendedStringOrig[64] = {0}; - char extendedStringBack[64] = {0}; - - snprintf(extendedStringOrig, 64, gDefaultKeyValueTestData[i], gOrigPostfix); - snprintf(extendedStringBack, 64, gDefaultKeyValueTestData[i], gBackupPostfix); - - - /*printf("Reference: %s\n", extendedStringOrig); - printf(" found: %s\n",buffer);*/ - - // check if original or backup will be used - if(0 == strncmp(extendedStringOrig, buffer, LC_CNT_START)) - { - /* - printf("ORIGINAL detected, everything OK:\n"); - printf(" desired: %s\n", extendedStringOrig); - printf(" actual : %s\n", buffer);*/ - } - else if(0 == strncmp(extendedStringBack, buffer, LC_CNT_START)) - { - /* - printf("BACKUP detected, everything OK:\n"); - printf(" desired: %s\n", extendedStringBack); - printf(" actual : %s\n", buffer); */ - } - else - { - - printf("----------------------------------------------------\n"); - printf("!!!! F A I L U R E !!!!! => lifecycle count - current: %d - found: %d\n", gLifecycleCounter, lc_count); - printf(" desired: %s\n", gDefaultKeyValueTestData[i]); - printf(" actual : %s\n", buffer); - printf("----------------------------------------------------\n"); - } - - -#if 0 - if(lc_count != (gLifecycleCounter-1) ) - { - printf(" Failure - LC count - current: %d - previous: %d - \"%s\"\n", gLifecycleCounter, lc_count, buffer); - /*DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("Failure - LC count - current:"), DLT_INT(gLifecycleCounter), - DLT_STRING("- previous:"), DLT_INT(lc_count), - DLT_STRING("- buf:"), DLT_STRING(buffer));*/ - } -#endif - - } - else - { - printf(" Failure - base string does not match - actual: \"%s\" - desired: \"%s\"\n", buffer, gDefaultKeyValueTestData[i]); - /*DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("Failure - base string does not match - actual: "), DLT_STRING(buffer), - DLT_STRING("- desired:"), DLT_STRING(gDefaultKeyValueTestData[i]));*/ - } - - } - } - printf("Persistence pfs test - verification ended!!!!\n"); -} - - -void write_data_key_value(int numLoops, int counter) -{ - int i=0, k=0, ret = 0; - - if( (counter%2) == 1) - { - printf("Corrupt Data: numLoops: %d!!!!\n", numLoops); - } - else - { - printf("Do N O T corrupt data!!!\n"); - } -#if 1 - for(k=0; k<numLoops; k++) - { - // write key/value data - - for(i=0; i< (int)sizeof(gDefaultKeyValueTestData) / (int)sizeof(char*); i++) - { - char buffer[64] = {0}; - - strncpy(buffer, gDefaultKeyValueTestData[i], 64); - update_test_data(buffer, gLifecycleCounter, k); - - if( (k == (int)numLoops/((counter%20)+1)) - && (counter%2 == 1)) - { - // unlock mutex - printf("Now POWER OFF => k: %d \n", k); -#if 0 - pcl_test_send_shutdown_command(); -#endif - break; - } - ret = pclKeyWriteData(PCL_LDBID_LOCAL, gDefaultKeyValueResName[i], 1, 1, (unsigned char*)buffer, strlen(buffer)); - if(ret < 0) - { - printf(" failed to write data: %d\n", ret ); - //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("write key/value - failed to write data"), DLT_INT(ret)); - } - - //printf("write data - key/value - \"%s\"\n", buffer); - } - } //num writes per lifecycle - - printf("End of Test\n"); -#endif -} - - - -void verify_data_file() -{ - int i=0, ret = 0; - int handles[128] = {0}; - char buffer[64] = {0}; - - // open files - for(i=0; i< (int)sizeof(gDefaultFileAPITestData) / (int)sizeof(char*); i++) - { - handles[i] = pclFileOpen(PCL_LDBID_LOCAL, gDefaultFileResNames[i], 1, 0); - } - - // read data from previous lifecycle - file - for(i=0; i< (int)sizeof(gDefaultFileAPITestData) / (int)sizeof(char*); i++) - { - memset(buffer, 0, 64); - ret = pclFileReadData(handles[i], buffer, 64); - if(ret < 0) - { - //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("verify data - file - failed to read data"), DLT_INT(ret)); - } - else - { - printf("verify file - file - \"%s\"\n", buffer); - //DLT_LOG(gPFSDLTContext, DLT_LOG_INFO, DLT_STRING("verify file: "), DLT_STRING(buffer)); - } - } - - // close fd's - for(i=0; i< (int)sizeof(gDefaultFileAPITestData) / (int)sizeof(char*); i++) - { - ret = pclFileClose(handles[i]); - if(ret != 0) - { - //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("close file - failed to close"), DLT_INT(ret)); - } - } -} - - -void write_data_file(int numLoops) -{ - int i=0, k=0, ret = 0; - int handles[128] = {0}; - - // open files - for(i=0; i< (int)sizeof(gDefaultFileAPITestData) / (int)sizeof(char*); i++) - { - handles[i] = pclFileOpen(PCL_LDBID_LOCAL, gDefaultFileResNames[i], 1, 1); - } - - for(k=0; k<numLoops; k++) - { - // write file data - - for(i=0; i< (int)sizeof(gDefaultFileAPITestData) / (int)sizeof(char*); i++) - { - char buffer[64] = {0}; - - strncpy(buffer, gDefaultFileAPITestData[i], 64); - update_test_data(buffer, gLifecycleCounter, k); - - //DLT_LOG(gPFSDLTContext, DLT_LOG_INFO, DLT_STRING("- write file:"), DLT_STRING(buffer)); - printf("write data - file - \"%s\"\n", buffer); - - ret = pclFileWriteData(handles[i], buffer, strlen(buffer)); - if(ret < 0) - { - //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("write file - failed to write data"), DLT_INT(ret)); - } - usleep((int)(rand()/100000)); // sleep a time random period - pclFileSeek(handles[i], 0, SEEK_SET); - } - - } // writes per lifecycle - - // close fd's - for(i=0; i< (int)sizeof(gDefaultFileAPITestData) / (int)sizeof(char*); i++) - { - ret = pclFileClose(handles[i]); - if(ret != 0) - { - //DLT_LOG(gPFSDLTContext, DLT_LOG_ERROR, DLT_STRING("close file - failed to close"), DLT_INT(ret)); - } - } -} - - - -void unmount_persistence() -{ - if(umount2("/Data/mnt-c", MNT_DETACH) == -1) - { - printf("unmount /Data/mnt-c - FAILED: %s\n", strerror(errno)); - } - - if(umount2("/Data/mnt-wt", MNT_DETACH) == -1) - { - printf("unmount /Data/mnt-wt - FAILED: %s\n", strerror(errno)); - } - -} - -int mount_persistence(const char* deviceName) -{ - int rval = 0; - - printf("Mount - /Data/mnt-c\n"); - if(-1 != mount(deviceName, "/Data/mnt-c", "ext4", 0, "")) - { - printf("Mount - /Data/mnt-wt\n"); - if(-1 == mount(deviceName, "/Data/mnt-wt", "ext4", 0, "")) - { - printf("Mount - FAILED - mnt-wt: %s\n", strerror(errno)); - rval = -1; - } - else - { - printf("Mount - SUCCESS\n"); - } - } - else - { - printf("Mount - FAILED - mnt-c: %s\n", strerror(errno)); - rval = -1; - } - - return rval; -} |