summaryrefslogtreecommitdiffstats
path: root/testsuites/psxtests
diff options
context:
space:
mode:
authorVaibhav Gupta <vaibhavgupta40@gmail.com>2019-07-23 19:11:54 +0530
committerJoel Sherrill <joel@rtems.org>2019-07-30 10:18:09 -0500
commit57e0173584a914b1a92aa73deade6afb463186db (patch)
tree1fe51973e29e9447fd929c565b2288e5a12b18d8 /testsuites/psxtests
parentarm/raspberrypi: Fix linker map (diff)
downloadrtems-57e0173584a914b1a92aa73deade6afb463186db.tar.bz2
psxtests: Add ndbm test suite
Joel Sherrill <joel@rtems.org> modified the patch to add autoconf logic to avoid building this new test unless the tool chain include <ndbm.h>. The ensures that git bisect continues to work and that the addition of this test does not immediately force the entire community to update their tools.
Diffstat (limited to 'testsuites/psxtests')
-rwxr-xr-xtestsuites/psxtests/Makefile.am11
-rw-r--r--testsuites/psxtests/configure.ac4
-rw-r--r--testsuites/psxtests/psxndbm01/init.c299
-rw-r--r--testsuites/psxtests/psxndbm01/psxndbm01.doc36
-rw-r--r--testsuites/psxtests/psxndbm01/psxndbm01.scn29
5 files changed, 379 insertions, 0 deletions
diff --git a/testsuites/psxtests/Makefile.am b/testsuites/psxtests/Makefile.am
index 59c9f2085b..c12b03636d 100755
--- a/testsuites/psxtests/Makefile.am
+++ b/testsuites/psxtests/Makefile.am
@@ -694,6 +694,17 @@ psxmutexattr01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_psxmutexattr01) \
$(support_includes) -I$(top_srcdir)/include
endif
+if HAS_NDBM
+if TEST_psxndbm01
+psx_tests += psxndbm01
+psx_screens += psxndbm01/psxndbm01.scn
+psx_docs += psxndbm01/psxndbm01.doc
+psxndbm01_SOURCES = psxndbm01/init.c
+psxndbm01_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_FLAGS_psxndbm01) \
+ $(support_includes)
+endif
+endif
+
if TEST_psxobj01
psx_tests += psxobj01
psx_screens += psxobj01/psxobj01.scn
diff --git a/testsuites/psxtests/configure.ac b/testsuites/psxtests/configure.ac
index 85559e4aa5..bb44bb8883 100644
--- a/testsuites/psxtests/configure.ac
+++ b/testsuites/psxtests/configure.ac
@@ -36,6 +36,9 @@ AM_CONDITIONAL([HAS_CPLUSPLUS],[test x"$HAS_CPLUSPLUS" = x"yes"])
RTEMS_CHECK_CPUOPTS([RTEMS_POSIX_API])
AM_CONDITIONAL(HAS_POSIX,test x"${rtems_cv_RTEMS_POSIX_API}" = x"yes")
+AC_CHECK_HEADER([ndbm.h]. [HAS_NDBM=yes], [HAS_NDBM=no])
+AM_CONDITIONAL(HAS_NDBM,test x"${ac_cv_header_ndbm_h__HAS_NDBM_yes}" = x"yes")
+
# BSP Test configuration
RTEMS_TEST_CHECK([psx01])
RTEMS_TEST_CHECK([psx02])
@@ -110,6 +113,7 @@ RTEMS_TEST_CHECK([psxmsgq02])
RTEMS_TEST_CHECK([psxmsgq03])
RTEMS_TEST_CHECK([psxmsgq04])
RTEMS_TEST_CHECK([psxmutexattr01])
+RTEMS_TEST_CHECK([psxndbm01])
RTEMS_TEST_CHECK([psxobj01])
RTEMS_TEST_CHECK([psxonce01])
RTEMS_TEST_CHECK([psxpasswd01])
diff --git a/testsuites/psxtests/psxndbm01/init.c b/testsuites/psxtests/psxndbm01/init.c
new file mode 100644
index 0000000000..a0b918c183
--- /dev/null
+++ b/testsuites/psxtests/psxndbm01/init.c
@@ -0,0 +1,299 @@
+/**
+ * @file
+ * @brief Test suite for ndbm.h methods
+ */
+
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (C) 2019 Vaibhav Gupta
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* header files are listed in lexical/lexicographical/alphabetical order */
+
+#include <errno.h>
+#include <fcntl.h> /* contains definitions of 'open_flags' */
+#include <limits.h>
+#include <ndbm.h> /* contains declarations of ndbm methods */
+#include <stddef.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <sys/stat.h> /* contains definitions of 'file_mode' */
+#include <string.h>
+#include <rtems/test.h>
+#include <tmacros.h>
+
+const char rtems_test_name[] = "PSXNDBM 01";
+
+#define NAME "VARoDeK"
+#define PHONE_NO "123-321-777-888"
+#define DB_NAME "phones_test"
+#define NAME2 "VG"
+#define PHONE_NO2 "321-123-888-777"
+
+/* forward declarations to avoid warnings */
+rtems_task Init(rtems_task_argument ignored);
+
+/*
+* This Function takes DBM* as a argument and count the number of records in the
+* database pointed by it.
+*/
+static int count_no_of_records( DBM *db_local )
+{
+ int count = 0;
+ datum temp;
+
+ for (
+ temp = dbm_firstkey( db_local );
+ temp.dptr != NULL;
+ temp = dbm_nextkey( db_local ), count++
+ );
+
+ return count;
+}
+
+/* Test Function Begins */
+rtems_task Init(rtems_task_argument ignored)
+{
+ datum name = { NAME, sizeof( NAME ) };
+ datum put_phone_no = { PHONE_NO, sizeof( PHONE_NO ) };
+ datum name2 = { NAME2, sizeof( NAME2 ) };
+ datum put_phone_no2 = { PHONE_NO2, sizeof( PHONE_NO2 ) };
+
+ datum get_phone_no, key;
+
+ int i;
+ char *test_strings;
+
+ DBM *db;
+
+ TEST_BEGIN();
+
+/* A Simple test to check if ndbm methods are call-able */
+
+/*
+ * A Simple test to check if NDBM methods are call-able
+ *
+ * We will try to open a database and then close it.
+ * If it successful, hence we can have further tests.
+ * Also, while opening it for first time, will create that database,
+ * hence we will be able to test for 'O_RDWR | O_EXCL' case later.
+ * Meanwhile we will also store one record, this record will be helpful in
+ * further tests.
+ * And fetch it, to make sure if basic NDBM methods are working correctly.
+ */
+
+ puts( "\nOpen Database." );
+ db = dbm_open( DB_NAME, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU );
+ rtems_test_assert( db != NULL );
+
+ /* This data will be useful in further tests */
+ puts( "Store Records in Database." );
+ dbm_store( db, name, put_phone_no, DBM_INSERT );
+
+ puts( "Fetch Records from Database and check." );
+ get_phone_no = dbm_fetch( db, name );
+ rtems_test_assert( strcmp( (const char*)get_phone_no.dptr, PHONE_NO ) == 0 );
+
+ puts( "Close Database." );
+ dbm_close( db );
+
+/* dbm_open() */
+
+ puts( "\nTestcases for 'dbm_open()'." );
+
+/* The 'DB_NAME' is already created, hence 'O_RDWR | O_EXCL' should fail. */
+ puts( "Use 'O_CREAT | O_EXCL' to open existing file and confirm error." );
+ db = dbm_open( DB_NAME, O_RDWR | O_CREAT | O_EXCL, S_IRWXU );
+ rtems_test_assert( db == NULL );
+ rtems_test_assert( errno == EEXIST );
+
+/* Some implementations use 3 characters for the suffix and others use
+ * 4 characters for the suffix, applications should ensure that the maximum
+ * portable pathname length passed to dbm_open() is no greater than
+ * {PATH_MAX}-4 bytes, with the last component of the pathname no greater
+ * than {NAME_MAX}-4 bytes.
+ */
+
+/* inside 'ndbm.h' ; '#define DBM_SUFFIX ".db"' ;
+ * 2 alphabets and 1 period, hence 3 characters are used for suffix
+ * in this implementation.
+ */
+
+ puts( "Use path name larger than '{PATH_MAX}-3 bytes.' and confirm error." );
+ test_strings = (char*)malloc( PATH_MAX - 2 );
+ for ( i = 0; i < PATH_MAX - 3; i++ ) {
+ test_strings[i] = 'r';
+ }
+ test_strings[i] = '\0';
+ db = dbm_open(
+ (const char*)test_strings,
+ O_RDWR | O_CREAT | O_TRUNC,
+ S_IRWXU
+ );
+ rtems_test_assert( db == NULL );
+ rtems_test_assert( errno == ENAMETOOLONG );
+ free( test_strings );
+
+/* database opened for write-only access opens the files for read and
+ * write access or it will fail.
+ */
+
+/* Implementation of __hash_open in newlib does not support `O_WRONLY` */
+
+ puts( "Open file with write access only and confirm error." );
+ db = dbm_open( DB_NAME, O_WRONLY, S_IRWXU );
+ rtems_test_assert( db == NULL );
+ rtems_test_assert( errno == EINVAL );
+
+/* dbm_store() */
+
+ puts( "\nTestcases for 'dbm_store()'" );
+ db = dbm_open( DB_NAME, O_RDWR, S_IRWXU );
+ rtems_test_assert( db != NULL );
+
+ puts( "Insert new record with same key using 'DBM_INSERT' mode and "
+ "confirm error." );
+ rtems_test_assert( dbm_store( db, name, put_phone_no2, DBM_INSERT ) == 1 );
+
+ get_phone_no = dbm_fetch( db, name );
+ rtems_test_assert( strcmp( (const char*)get_phone_no.dptr, PHONE_NO ) == 0 );
+
+ puts( "Insert new record with same key using 'DBM_REPLACE' mode and "
+ "confirm changes." );
+ rtems_test_assert( dbm_store( db, name, put_phone_no2, DBM_REPLACE ) == 0 );
+
+ get_phone_no = dbm_fetch( db, name );
+ rtems_test_assert( strcmp( (const char*)get_phone_no.dptr, PHONE_NO2 ) == 0 );
+
+/* Revert for next tests */
+ rtems_test_assert( dbm_store( db, name, put_phone_no, DBM_REPLACE ) == 0 );
+
+ puts( "Store a new record and "
+ "confirm that total number of records is successful 2." );
+ rtems_test_assert( dbm_store( db, name2, put_phone_no2, DBM_INSERT ) == 0 );
+
+/* Confirm number of records */
+ rtems_test_assert( count_no_of_records( db ) == 2 );
+
+ dbm_close( db );
+
+/* dbm_fetch() */
+
+ puts( "\nTestcases for 'dbm_fetch()'" );
+ db = dbm_open( DB_NAME, O_RDONLY, S_IRWXU );
+ rtems_test_assert( db != NULL );
+
+ puts( "Fetch existing records and confirm results." );
+ get_phone_no = dbm_fetch( db, name );
+ rtems_test_assert( strcmp( (const char*)get_phone_no.dptr, PHONE_NO ) == 0 );
+
+ get_phone_no = dbm_fetch( db, name2 );
+ rtems_test_assert( strcmp( (const char*)get_phone_no.dptr, PHONE_NO2 ) == 0 );
+
+ puts( "Fetch non-existing record and confirm error." );
+ test_strings = (char*)malloc(6);
+ strncpy( test_strings, "Hello", 5 );
+
+ test_strings[5] = '\0';
+
+/* The data pointed by test_string is now pointed by key.dptr */
+ key.dptr = test_strings;
+ key.dsize = sizeof( test_strings );
+ get_phone_no = dbm_fetch( db, key );
+ rtems_test_assert( get_phone_no.dptr == NULL );
+ dbm_close( db );
+
+/* We need the 'key' object, hence we cannot free 'test_strings' */
+
+/* dbm_delete() */
+
+ puts( "\nTestcases for 'dbm_delete()'" );
+ db = dbm_open( DB_NAME, O_RDWR, S_IRWXU );
+ rtems_test_assert( db != NULL );
+
+ puts( "Delete non-existing record and confirm error." );
+ rtems_test_assert( dbm_delete( db, key ) != 0 );
+ free( test_strings );
+ rtems_test_assert( count_no_of_records( db ) == 2);
+
+ puts( "Delete existing record and "
+ "confirm that total number of records is successful 1." );
+ rtems_test_assert( dbm_delete( db, name ) == 0 );
+ rtems_test_assert( count_no_of_records( db ) == 1);
+
+ puts( "Confirm if correct record is deleted." );
+ get_phone_no = dbm_fetch( db, name );
+ rtems_test_assert( get_phone_no.dptr == NULL );
+
+/* record returned by 'dbm_firstkey()' should be the only record
+ * left, this should be checked to confirm correct working of
+ * 'dbm_firstkey()'.
+ * Check if the data is not corrupted after usage of 'dbm_delete()'
+ */
+
+ puts( "Check if the data is not corrupted after usage of 'dbm_delete()'." );
+ get_phone_no = dbm_fetch( db, dbm_firstkey( db ) );
+ rtems_test_assert( strcmp( (const char*)get_phone_no.dptr, PHONE_NO2 ) == 0 );
+
+/* Empty the database and then try to use 'dbm_firstkey()', the
+ * dptr pointer should point to NULL.
+ */
+
+ puts( "Empty records in database and check results of 'dbm_firstkey()'." );
+ rtems_test_assert( dbm_delete( db, dbm_firstkey( db ) ) == 0 );
+ key = dbm_firstkey( db );
+ rtems_test_assert( key.dptr == NULL );
+ dbm_close( db );
+
+/*
+* All cases for 'dbm_firstkey()' and 'dbm_nextkey()' were tested while
+* performing other tests.
+* One such case be found in count_number_of_records() function.
+*/
+
+ TEST_END();
+ rtems_test_exit(0);
+}
+
+/* NOTICE: the clock driver is explicitly disabled */
+
+#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+
+#define CONFIGURE_MAXIMUM_TASKS 1
+
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 6
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
+
+#define CONFIGURE_INIT
+#include <rtems/confdefs.h>
+/* end of file */
diff --git a/testsuites/psxtests/psxndbm01/psxndbm01.doc b/testsuites/psxtests/psxndbm01/psxndbm01.doc
new file mode 100644
index 0000000000..cdaeb40911
--- /dev/null
+++ b/testsuites/psxtests/psxndbm01/psxndbm01.doc
@@ -0,0 +1,36 @@
+This File describes the concepts tested by this test suite.
+
+ndbm.h - routines to manage data files that contain key/data pairs.
+
+test suite name: PSXNDBM 01
+
+- A Simple test to check if NDBM methods are call-able.
+ - Check if able to run the routine to Open Database.
+ - Check if able to run the routine to store a record in database.
+ - Check if able to run the routine to fetch a record from database.
+ - Check if able to run the routine to close the database.
+
+- Test Cases for 'dbm_open()'.
+ - Verify the error when trying to open existing file with 'O_RDWR | O_EXCL'
+ flags.
+ - Verify the error when trying to open file with pathname longer than
+ {PATHMAX}-3 bytes.
+ - Verify the error when trying to open file with only write access.
+
+- Test Cases for 'dbm_store()'.
+ - Verify the error when trying to insert a record using same key with
+ 'DBM_INSERT' mode.
+ - Verify the updated record when trying to insert a record using same key
+ with 'DBM_REPLACE' mode.
+ - Verify if able to save more than one record in database.
+
+- Test Cases for 'dbm_fetch()'.
+ - Verify the data fetched from database.
+ - Verify the error when tring to fetch non-existing record.
+
+- Test Cases for 'dbm_delete()'.
+ - Veriy the error when trying to delete non-existing record.
+ - Delete one record and verify results.
+ - Check if correct record is deleted.
+ - Verify if other data is not corrupted during delete.
+ - Empty the databse and verify the value returned by 'dbm_firstkey()'. \ No newline at end of file
diff --git a/testsuites/psxtests/psxndbm01/psxndbm01.scn b/testsuites/psxtests/psxndbm01/psxndbm01.scn
new file mode 100644
index 0000000000..3fa386630a
--- /dev/null
+++ b/testsuites/psxtests/psxndbm01/psxndbm01.scn
@@ -0,0 +1,29 @@
+*** PSXNDBM 01 Test ***
+
+Open Database.
+Store Records in Database.
+Fetch Records from Database and check.
+Close Database.
+
+Testcases for 'dbm_open()'.
+Use 'O_CREAT | O_EXCL' to open existing file and confirm error.
+Use path name larger than '{PATH_MAX}-3 bytes.' and confirm error.
+Open file with write access only and confirm error.
+
+Testcases for 'dbm_store()'
+Insert new record with same key using 'DBM_INSERT' mode and confirm error.
+Insert new record with same key using 'DBM_REPLACE' mode and confirm changes.
+Store a new record and confirm that total number of records is successful 2.
+
+Testcases for 'dbm_fetch()'
+Fetch existing records and confirm results.
+Fetch non-existing record and confirm error.
+
+Testcases for 'dbm_delete()'
+Delete non-existing record and confirm error.
+Delete existing record and confirm that total number of records is successful 1.
+Confirm if correct record is deleted.
+Check if the data is not corrupted after usage of 'dbm_delete()'.
+Empty records in database and check results of 'dbm_firstkey()'.
+
+*** END OF TEST PSXNDBM 01 *** \ No newline at end of file