mirror of
https://github.com/nasa/trick.git
synced 2025-06-24 01:28:46 +00:00
Allow for read only S_sie.resource (#1420)
This commit is contained in:
2
trick_source/sim_services/CommandLineArguments/test/.gitignore
vendored
Normal file
2
trick_source/sim_services/CommandLineArguments/test/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
create_path_test
|
||||
*.o
|
42
trick_source/sim_services/CommandLineArguments/test/Makefile
Normal file
42
trick_source/sim_services/CommandLineArguments/test/Makefile
Normal file
@ -0,0 +1,42 @@
|
||||
|
||||
#SYNOPSIS:
|
||||
#
|
||||
# make [all] - makes everything.
|
||||
# make TARGET - makes the given target.
|
||||
# make clean - removes all files generated by make.
|
||||
|
||||
include $(dir $(lastword $(MAKEFILE_LIST)))../../../../share/trick/makefiles/Makefile.common
|
||||
|
||||
# Replace -isystem with -I so ICG doesn't skip Trick headers
|
||||
TRICK_SYSTEM_CXXFLAGS := $(subst -isystem,-I,$(TRICK_SYSTEM_CXXFLAGS))
|
||||
|
||||
# Flags passed to the preprocessor.
|
||||
TRICK_CXXFLAGS += -I$(GTEST_HOME)/include -I$(TRICK_HOME)/include -g -Wall -Wextra -std=c++11 ${TRICK_SYSTEM_CXXFLAGS} ${TRICK_TEST_FLAGS}
|
||||
|
||||
# so it seems like there's some weirdness linking in the bitfield objects since they are C
|
||||
MM_OBJECTS = $(TRICK_HOME)/trick_source/sim_services/MemoryManager/object_${TRICK_HOST_CPU}/extract_bitfield.o \
|
||||
$(TRICK_HOME)/trick_source/sim_services/MemoryManager/object_${TRICK_HOST_CPU}/extract_unsigned_bitfield.o
|
||||
|
||||
TRICK_LIBS = -L${TRICK_LIB_DIR} -ltrick_mm -ltrick_units -ltrick -ltrick_mm -ltrick_units -ltrick
|
||||
TRICK_EXEC_LINK_LIBS += -L${GTEST_HOME}/lib64 -L${GTEST_HOME}/lib -lgtest -lgtest_main -lpthread
|
||||
|
||||
|
||||
# All tests produced by this Makefile. Remember to add new tests you
|
||||
# created to the list.
|
||||
TESTS = create_path_test
|
||||
|
||||
# House-keeping build targets.
|
||||
|
||||
all : $(TESTS)
|
||||
|
||||
test: $(TESTS)
|
||||
./create_path_test --gtest_output=xml:${TRICK_HOME}/trick_test/create_path_test.xml
|
||||
|
||||
clean :
|
||||
rm -f $(TESTS) *.o *.gcno *.gcda
|
||||
|
||||
create_path_test.o : create_path_test.cpp
|
||||
$(TRICK_CXX) $(TRICK_CXXFLAGS) -c $<
|
||||
|
||||
create_path_test : create_path_test.o $(MM_OBJECTS)
|
||||
$(TRICK_CXX) $(TRICK_SYSTEM_LDFLAGS) -o $@ $^ -L${TRICK_HOME}/lib_${TRICK_HOST_CPU} $(TRICK_LIBS) $(TRICK_EXEC_LINK_LIBS)
|
@ -0,0 +1,99 @@
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "trick/CommandLineArguments.hh"
|
||||
|
||||
namespace Trick {
|
||||
|
||||
|
||||
// Clean up the directory created
|
||||
void rm_dir(const std::string& dir) {
|
||||
const int result = remove( dir.c_str() );
|
||||
if( result != 0 && errno == 66){
|
||||
// Failed because directory is not empty
|
||||
// Remove stuff and try again
|
||||
DIR *temp_dir;
|
||||
struct dirent *ent;
|
||||
if ((temp_dir = opendir (dir.c_str())) != NULL) {
|
||||
// Go through everything in this directory
|
||||
while ((ent = readdir (temp_dir)) != NULL) {
|
||||
if (!(strcmp(".", ent->d_name) == 0 || strcmp("..", ent->d_name) == 0 )) {
|
||||
// remove it
|
||||
rm_dir(dir + "/" + std::string(ent->d_name));
|
||||
}
|
||||
}
|
||||
closedir (temp_dir);
|
||||
}
|
||||
|
||||
// Try again
|
||||
remove( dir.c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
bool dir_correct(const std::string& dir) {
|
||||
// Make sure that the directory exists and is writeable
|
||||
struct stat info;
|
||||
if(stat( dir.c_str(), &info ) == 0) {
|
||||
if (info.st_mode & S_IFDIR && info.st_mode & S_IWUSR ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
TEST(CreatePathTest, BasicTest) {
|
||||
std::string dir = "a/b/c";
|
||||
ASSERT_EQ(CommandLineArguments::create_path(dir), 0);
|
||||
ASSERT_TRUE(dir_correct(dir));
|
||||
|
||||
rm_dir("a");
|
||||
}
|
||||
|
||||
TEST(CreatePathTest, PreExistingDir) {
|
||||
std::string dir = "pre_existing_output_dir";
|
||||
ASSERT_EQ(CommandLineArguments::create_path(dir), 0);
|
||||
ASSERT_TRUE(dir_correct(dir));
|
||||
}
|
||||
|
||||
TEST(CreatePathTest, PreExistingInPath) {
|
||||
std::string dir = "pre_existing_output_dir/a/b/c";
|
||||
ASSERT_EQ(CommandLineArguments::create_path(dir), 0);
|
||||
ASSERT_TRUE(dir_correct(dir));
|
||||
|
||||
rm_dir("pre_existing_output_dir/a");
|
||||
}
|
||||
|
||||
TEST(CreatePathTest, FileInPath) {
|
||||
std::string dir = "pre_existing_output_dir/some_file/a";
|
||||
ASSERT_EQ(CommandLineArguments::create_path(dir), 1);
|
||||
}
|
||||
|
||||
|
||||
TEST(CreatePathTest, AbsolutePath) {
|
||||
char buf[1024];
|
||||
getcwd(buf, 1024);
|
||||
std::string dir = std::string(buf) + "/a/b/c";
|
||||
ASSERT_EQ(CommandLineArguments::create_path(dir), 0);
|
||||
ASSERT_TRUE(dir_correct(dir));
|
||||
|
||||
rm_dir(std::string(buf) + std::string("/a"));
|
||||
}
|
||||
|
||||
TEST(CreatePathTest, dotdotinpath) {
|
||||
std::string dir = "../a/b/c";
|
||||
ASSERT_EQ(CommandLineArguments::create_path(dir), 0);
|
||||
ASSERT_TRUE(dir_correct(dir));
|
||||
|
||||
rm_dir("../a");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user