1
1

Add unit tests for os_create_dirpath and sys_info.

This commit was SVN r1157.
Этот коммит содержится в:
Ralph Castain 2004-05-26 02:20:05 +00:00
родитель bc8330fb7a
Коммит 5ed4721bb2
3 изменённых файлов: 239 добавлений и 1 удалений

Просмотреть файл

@ -8,6 +8,8 @@ AM_CPPFLAGS = -I$(top_srcdir)/test/support -DLAM_ENABLE_DEBUG_OVERRIDE=1
noinst_PROGRAMS = \
ompi_os_path \
ompi_sys_info \
ompi_os_create_dirpath \
lam_argv
lam_argv_SOURCES = lam_argv.c
@ -38,4 +40,37 @@ ompi_os_path_LDADD = \
$(top_builddir)/src/threads/mutex_spinwait.lo \
$(top_builddir)/src/util/os_path.lo \
$(top_builddir)/test/support/libsupport.la
ompi_os_path_DEPENDENCIES = $(lam_argv_LDADD)
ompi_os_path_DEPENDENCIES = $(ompi_os_path_LDADD)
ompi_sys_info_SOURCES = ompi_sys_info.c
ompi_sys_info_LDADD = \
$(top_builddir)/src/util/sys_info.lo \
$(top_builddir)/src/lfc/lam_object.lo \
$(top_builddir)/src/mem/malloc.lo \
$(top_builddir)/src/util/output.lo \
$(top_builddir)/src/util/argv.lo \
$(top_builddir)/src/util/strncpy.lo \
$(top_builddir)/src/threads/mutex.lo \
$(top_builddir)/src/threads/mutex_pthread.lo \
$(top_builddir)/src/threads/mutex_spinlock.lo \
$(top_builddir)/src/threads/mutex_spinwait.lo \
$(top_builddir)/test/support/libsupport.la
ompi_sys_info_DEPENDENCIES = $(ompi_sys_info_LDADD)
ompi_os_create_dirpath_SOURCES = ompi_os_create_dirpath.c
ompi_os_create_dirpath_LDADD = \
$(top_builddir)/src/util/sys_info.lo \
$(top_builddir)/src/lfc/lam_object.lo \
$(top_builddir)/src/mem/malloc.lo \
$(top_builddir)/src/util/output.lo \
$(top_builddir)/src/util/argv.lo \
$(top_builddir)/src/util/strncpy.lo \
$(top_builddir)/src/threads/mutex.lo \
$(top_builddir)/src/threads/mutex_pthread.lo \
$(top_builddir)/src/threads/mutex_spinlock.lo \
$(top_builddir)/src/threads/mutex_spinwait.lo \
$(top_builddir)/src/util/os_path.lo \
$(top_builddir)/src/util/os_create_dirpath.lo \
$(top_builddir)/test/support/libsupport.la
ompi_os_create_dirpath_DEPENDENCIES = $(ompi_os_create_dirpath_LDADD)

133
test/util/ompi_os_create_dirpath.c Обычный файл
Просмотреть файл

@ -0,0 +1,133 @@
/*
* $HEADER$
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/stat.h>
#include "lam_config.h"
#include "constants.h"
#include "util/sys_info.h"
#include "util/os_path.h"
#include "util/os_create_dirpath.h"
static bool test1(void); /* trivial test */
static bool test2(void); /* test existing path, both with and without correct mode */
static bool test3(void); /* test making a directory tree */
int main(int argc, char* argv[])
{
bool test1f, test2f, test3f;
test1f = test2f = test3f = false;
ompi_sys_info(); /* initialize system info */
/* All done */
if (test1()) {
printf("test1 passed\n");
test1f = true;
}
if (test2()) {
printf("test2 passed\n");
test2f = true;
}
if (test3()) {
printf("test3 passed\n");
test3f = true;
}
if (test1f && test2f && test3f) {
printf("test succeeded\n");
return 0;
}
printf("test failed\n");
return -1;
}
static bool test1(void)
{
/* Test trivial functionality. Program should return LAM_ERROR when called with NULL path. */
if (LAM_ERROR != ompi_os_create_dirpath(NULL, S_IRWXU))
return(false);
return true;
}
static bool test2(void)
{
char *tmp;
struct stat buf;
if (NULL == ompi_system_info.path_sep) {
printf("test2 cannot be run\n");
return(false);
}
tmp = ompi_os_path(true, "tmp", NULL);
if (0 != mkdir(tmp, S_IRWXU)) {
printf("test2 could not be run - directory could not be made\n");
return(false);
}
if (LAM_ERROR == ompi_os_create_dirpath(tmp, S_IRWXU)) {
rmdir(tmp);
return(false);
}
chmod(tmp, S_IRUSR);
if (LAM_ERROR == ompi_os_create_dirpath(tmp, S_IRWXU)) {
rmdir(tmp);
return(false);
}
stat(tmp, &buf);
if (S_IRWXU != (S_IRWXU & buf.st_mode)) {
rmdir(tmp);
return(false);
}
rmdir(tmp);
return true;
}
static bool test3(void)
{
char *out;
struct stat buf;
char *a[] = { "aaa", "bbb", "ccc", NULL };
if (NULL == ompi_system_info.path_sep) {
printf("test3 cannot be run\n");
return(false);
}
out = ompi_os_path(true, a[0], a[1], a[2], NULL);
if (LAM_ERROR == ompi_os_create_dirpath(out, S_IRWXU)) {
out = ompi_os_path(true, a[0], a[1], a[2], NULL);
if (0 == stat(out, &buf))
rmdir(out);
out = ompi_os_path(true, a[0], a[1], NULL);
if (0 == stat(out, &buf))
rmdir(out);
out = ompi_os_path(true, a[0], NULL);
if (0 == stat(out, &buf))
rmdir(out);
return(false);
}
return(true);
}

70
test/util/ompi_sys_info.c Обычный файл
Просмотреть файл

@ -0,0 +1,70 @@
/*
* $HEADER$
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/param.h>
#include "lam_config.h"
#include "util/sys_info.h"
static bool test1(void); /* verify it returns info */
static bool test2(void); /* test second time through */
int main(int argc, char* argv[])
{
bool test1f, test2f;
test1f = test2f = false;
/* All done */
if (test1()) {
printf("test1 passed\n");
test1f = true;
}
if (test2()) {
printf("test2 passed\n");
test2f = true;
}
if (test1f && test2f) {
printf("test succeeded\n");
return 0;
}
printf("test failed\n");
return -1;
}
static bool test1(void)
{
/* Test trivial functionality. Program should return with init=true and all ptrs non-NULL */
ompi_sys_info();
if (ompi_system_info.init == false)
return(false);
if (ompi_system_info.sysname == NULL ||
ompi_system_info.nodename == NULL ||
ompi_system_info.release == NULL ||
ompi_system_info.version == NULL ||
ompi_system_info.machine == NULL ||
ompi_system_info.path_sep == NULL)
return(false);
return true;
}
static bool test2(void)
{
/* test it a second time. system should return without crashing and with init=true */
ompi_sys_info();
return(ompi_system_info.init);
}