Skip to content

Commit

Permalink
support test only;
Browse files Browse the repository at this point in the history
add test for fileutility;
build docker on ubuntu1804 with binary.
  • Loading branch information
wulongict committed Jun 11, 2024
1 parent 4d7ed1f commit c314625
Show file tree
Hide file tree
Showing 12 changed files with 92 additions and 29 deletions.
14 changes: 3 additions & 11 deletions ArchiveSearch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Release)

link_directories(${CMAKE_BINARY_DIR}/Release ${fcgi_install_dir}/lib)

# set(CMAKE_INSTALL_RPATH "${ORIGIN}/lib")

# code can be moved to other places: might rely libraries in dependentlibs
add_subdirectory(dependentlibs)
include_directories(External)
Expand Down Expand Up @@ -52,18 +50,12 @@ msbasic_small_static mstoolkit spectrastlib_static

file(READ "${CMAKE_SOURCE_DIR}/version.txt" MY_SPECTROSCAPE_VERSION)

# target_compile_definitions(spectroscape PRIVATE SPECTROSCAPE_VERSION=${MY_SPECTROSCAPE_VERSION})
add_compile_definitions(SPECTROSCAPE_VERSION="${MY_SPECTROSCAPE_VERSION}")
target_compile_definitions(spectroscape PRIVATE SPECTROSCAPE_VERSION="${MY_SPECTROSCAPE_VERSION}")

add_dependencies(spectroscape boost ${DPGPU})

#The commandline tool for library search
#add_executable(LibraryRetrieval LibSearchEngine.cpp )
#target_link_libraries(LibraryRetrieval specarchive)

install(TARGETS spectroscape DESTINATION bin )
# install(TARGETS linear DESTINATION lib OPTIONAL)
# install(TARGETS msfileramp msbasic_small linear DESTINATION lib OPTIONAL)


set(CPACK_DEBIAN_PACKAGE_DEPENDS "libopenblas-dev,libgomp1,sqlite")
set(CPACK_PACKAGE_NAME Spectroscape_CPU)
Expand All @@ -79,7 +71,7 @@ set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION})

set(CPACK_DEBIAN_PACKAGE_MAINTAINER Long WU)
set(CPACK_OUTPUT_FILE_PREFIX ${CMAKE_SOURCE_DIR}/package)
set(CPACK_THREADS 0)
set(CPACK_THREADS 0) # USING MULTICORE.
SET(CPACK_GENERATOR "ZIP") #.ZIP
SET(CPACK_GENERATOR "STGZ" "DEB") #.sh #deb
SET(CPACK_SOURCE_GENERATOR "TBZ2")
Expand Down
15 changes: 4 additions & 11 deletions ArchiveSearch/FileUtility.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
#include "dependentlibs/msbasic/commonfun.h"
#include "dependentlibs/msbasic/CDebugMode.h"
#include "../librarymsms/CMzFileReader.h"
#include "FastCgiInterface.h"
#include "dependentlibs/spectralIndex/CKMeans.h"
#include "CSpectralArchive.h"
#include <thread>
#include "CTimerSummary.h"
#include "Util.h"
// #include <filesystem>
// namespace fs = std::filesystem;
#include <algorithm>
#include <iostream>
#include <string>
#include <boost/filesystem.hpp>
using namespace std;
namespace fs = boost::filesystem;

std::vector<fs::path> get_mz_file_list(const fs::path& dir_path) {
Expand Down
19 changes: 18 additions & 1 deletion ArchiveSearch/spectroscapeMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// namespace fs = std::filesystem;
#include <csignal>
#include <atomic>
#include <unistd.h>


#include <boost/filesystem.hpp>
Expand Down Expand Up @@ -208,7 +209,7 @@ boost::program_options::variables_map getParam(int argc, char *argv[]) {
("maxconnection", po::value<int>()->default_value(10),
"The port which socket to listen to. Default: port=10; "
"check /proc/sys/net/core/somaxconn for maximal number of connections allowed on local computer")
("wwwroot", po::value<string>()->default_value("./"),
("wwwroot", po::value<string>()->default_value(""),
"path of root folder of spectroscape web UI, config this to the SpectralArchiveWeb/arxiv folder. ")
("indexstring", po::value<string>()->default_value("IVF100,PQ8"),
"the string for index_factory() to build index")
Expand All @@ -233,6 +234,8 @@ boost::program_options::variables_map getParam(int argc, char *argv[]) {
po::positional_options_description p;
p.add("inputfile", -1);
po::store(po::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm);
// const int PATH_MAX = 4096;


// po::store(po::command_line_parser(argc, argv).options(visible).run(), visiable_vm);
bool run = vm["run"].as<bool>();
Expand Down Expand Up @@ -505,6 +508,20 @@ int main(int argc, char *argv[]) {
int initcenoption = vm.at("centroidinit").as<int>();
string indexstrs = vm.at("indexstrs").as<string>();
string wwwroot = vm.at("wwwroot").as<string>();
char buffer[PATH_MAX + 1];
ssize_t len = readlink("/proc/self/exe",buffer,PATH_MAX);

if(len!=-1){
buffer[len] = '\0';
// set_env_var("SPECTROSCAPE_PATH", path);
}
string path = fs::path(buffer).parent_path().string();
cout << "------------------------------------The path is " << path << endl;
if(wwwroot == ""){
wwwroot = (fs::path(buffer).parent_path().parent_path() / "www").string();
// set the path back to vm
cout << "The wwwroot is " << wwwroot << endl;
}
string indexshuffleseeds = vm.at("indexshuffleseeds").as<string>();
string gpuidx = vm.at("gpuidx").as<string>();
int tolerance = vm["tolerance"].as<int>();
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.20)
project(mytool LANGUAGES CXX)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++11 -fpermissive -fopenmp -fPIC -Wreturn-type -Werror=return-type ")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++11 -fpermissive -fopenmp -fPIC -Wreturn-type -Werror=return-type ")


set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/Release)
Expand Down
14 changes: 14 additions & 0 deletions compile.bash
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ show_help() {
echo " -g, --gpu compile GPU version, otherwise, CPU version; Default to CPU."
echo " -b, --build-type compile release version, otherwise, debug version, Default to release. "
echo " -c, --cores number of cores to use for compilation. Default to nproc / 16 + 1"
echo " -t, --test-only only compile and run tests"
echo " -h, --help display this help and exit"
echo ""
echo "Examples:"
Expand Down Expand Up @@ -66,6 +67,11 @@ while [[ $# -gt 0 ]]; do
shift # past argument
shift # past value
;;
-t|--test-only)
test_only="TRUE"
echo "test only"
shift # past argument
;;
-c|--cores)
cores="$2"
# limit core number to 1 to 128
Expand Down Expand Up @@ -136,6 +142,14 @@ cmake ${cmake_build_options} ..
# cmake --graphviz=foo.dot ..
# cmake ..

# if TEST_ONLY is set, only compile msmstest
if [ ${test_only} = "TRUE" ]; then
cmake --build ../${releasePath} --target msmstest -- -j $cores
ctest --verbose
echo "TEST ONLY RUN FINISHED."
exit 0
fi

cmake --build ../${releasePath} --target spectroscape msmstest using_all_cpu_cores -- -j $cores

# run tests added into CMakeLists.txt file with add_test(Name XXX Command YYY)
Expand Down
9 changes: 9 additions & 0 deletions docker/ubuntu1804bin/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# syntax=docker/dockerfile:1
FROM ubuntu:18.04

# install app dependencies
RUN apt update && apt install -y wget
RUN wget https://github.com/wulongict/SpectralArchive/releases/download/v1.2.0/Spectroscape_CPU-1.2.0.deb
RUN apt install -y ./Spectroscape_CPU-1.2.0.deb


23 changes: 23 additions & 0 deletions docker/ubuntu1804bin/create_docker_and_run.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# create the docker
docker build --no-cache -t spectroscape-ubuntu1804bin .

# docker run -it spectroscape-ubuntu2004:latest gcc --version
# run spectroscape
docker run -it spectroscape-ubuntu1804bin:latest spectroscape
output=$?
status="compiled successfully;"
if [ $output -eq 0 ]; then
echo "spectroscape run successfully"
# run the docker with bash
echo docker run -it --rm spectroscape-ubuntu1804bin:latest bash
else
status="compiled failed;"
echo "spectroscape run failed"
echo `date` `pwd` $status tested by Long > ../log.txt
fi




4 changes: 2 additions & 2 deletions scripts/start_service.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


archive_path="$HOME/data/spectroscape/spectral_archives_latest"
bin_path="$HOME/code/SpectralArchive/build/bin/spectroscape"
bin_path=`which spectroscape`
wwwroot_path="`dirname $bin_path`/../www"
cd $archive_path && spawn-fcgi -p 8710 -n -- $bin_path --run --wwwroot $wwwroot_path
cd $archive_path && spawn-fcgi -p 8710 -n -- $bin_path --run
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ project(tests)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -std=c++11 -fpermissive -fopenmp -fPIC -Wreturn-type -Werror=return-type ")

include_directories(../External/gtest-1.7.0/include ../librarymsms)
add_executable(msmstest msmstest.cpp)
add_executable(msmstest msmstest.cpp ../ArchiveSearch/FileUtility.cpp)
target_link_libraries(msmstest gtest_main gtest msbasic_small msfileramp_static)

add_executable(using_all_cpu_cores multiple-threads-usage.cpp
Expand Down
Empty file added tests/data/fileutility/x.mzXML
Empty file.
Empty file added tests/data/fileutility/y.mzML
Empty file.
19 changes: 17 additions & 2 deletions tests/msmstest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,25 @@ TEST(FILE_SEARCH, SPEED_TEST){
cin >> filename;
}

}



#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
#include "../ArchiveSearch/FileUtility.h"

TEST(FILE_SEARCH, FILE_SEARCH){
// fs::path dir = "../tests/data";
fs::path dir = "../tests/data/fileutility";
vector<string> ext_list = {".mzxml", ".mzml", ".tsv"};
vector<fs::path> file_list = get_file_list(dir, ext_list);
cout << "file list size " << file_list.size() << endl;
for(auto file: file_list){
cout << file.string() << endl;
}
ASSERT_EQ(2, file_list.size());
}

// create test for function in FileUtility.cpp



0 comments on commit c314625

Please sign in to comment.