Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1410,6 +1410,9 @@ if(BUILD_TESTING)
add_subdirectory(mdstcpip/testing)
add_subdirectory(tditest/testing)
add_subdirectory(wfevent/testing)
if(TARGET cts_commands)
add_subdirectory(camshr/testing)
endif()
add_subdirectory(mdsobjects/cpp/testing)
add_subdirectory(python/MDSplus/tests)

Expand Down
24 changes: 24 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,30 @@ distributions['MATLAB'] = localTest('MATLAB', 'linux-amd64', {
}
})

distributions['CAMSHR SQLite'] = localTest('CAMSHR SQLite', 'linux-amd64', {
stage("Test") {
try {
sh '''
set -eu
ctest -N --test-dir workspace/build > workspace/camshr-sqlite-tests.txt
grep -q "camshr/testing/camshr_crate_state_fakehw_test" workspace/camshr-sqlite-tests.txt
grep -q "camshr/testing/camshr_backend_policy_test" workspace/camshr-sqlite-tests.txt
grep -q "camshr/testing/camshr_sqlite_schema_test" workspace/camshr-sqlite-tests.txt
grep -q "camshr/testing/camshr_sqlite_migration_test" workspace/camshr-sqlite-tests.txt
grep -q "camshr/testing/camshr_sqlite_backend_roundtrip_test" workspace/camshr-sqlite-tests.txt
grep -q "camshr/testing/camshr_autoconfig_sqlite_fakeproc_test" workspace/camshr-sqlite-tests.txt
'''
sh """
CAMSHR_DB_BACKEND=sqlite deploy/build.py --workspace=workspace --no-configure --no-build --test \
--output-junit --junit-suite-name='camshr-sqlite'
"""
}
finally {
junit skipPublishingChecks: true, testResults: "workspace/mdsplus-junit.xml", keepLongStdio: true
}
}
})

def AdminList = [
'dgarnier',
'GabrieleManduchi',
Expand Down
19 changes: 18 additions & 1 deletion camshr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ if(HAVE_SCSI_SG_H AND NOT MSVC)
CamShr
add_entry.c
bisearch.c
camac_db_backend.c
camac_db_sqlite.c
camac_hw_iface.c
cam_functions.c
check_for_file.c
check_sema4.c
Expand Down Expand Up @@ -60,6 +63,20 @@ if(HAVE_SCSI_SG_H AND NOT MSVC)
MdsIpShr
)

find_package(SQLite3)
if(SQLite3_FOUND)
target_compile_definitions(
CamShr
PRIVATE
CAMSHR_HAVE_SQLITE3=1
)
target_link_libraries(
CamShr
PRIVATE
SQLite::SQLite3
)
endif()

set_target_properties(
CamShr
PROPERTIES
Expand Down Expand Up @@ -107,4 +124,4 @@ if(HAVE_SCSI_SG_H AND NOT MSVC)
PERMISSIONS ${MODE_755}
)

endif()
endif()
4 changes: 3 additions & 1 deletion camshr/Makefile.bak
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ SHLIB_BUILD = $(top_srcdir)/lib64/$(SHLIB)
SOURCES = \
add_entry.c \
bisearch.c \
camac_db_backend.c \
camac_db_sqlite.c \
camac_hw_iface.c \
cam_functions.c \
check_for_file.c \
check_sema4.c \
Expand Down Expand Up @@ -94,4 +97,3 @@ $(SHLIB_BUILD) $(IMPLIB): $(OBJECTS)
$(LINK.c) -shared -nostartfiles -Wl,-soname=$(SHLIB) -o $@.$(MAJOR).$(MINOR) $^ -L$(top_srcdir)/lib64/ -lMdsShr $(MAKE_IMPLIB)
ln -sf $(SHLIB).$(MAJOR).$(MINOR) $@.$(MAJOR)
ln -sf $(SHLIB).$(MAJOR) $@

4 changes: 3 additions & 1 deletion camshr/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ SHLIB_BUILD = @MAKESHLIBDIR@$(SHLIB)
SOURCES = \
add_entry.c \
bisearch.c \
camac_db_backend.c \
camac_db_sqlite.c \
camac_hw_iface.c \
cam_functions.c \
check_for_file.c \
check_sema4.c \
Expand Down Expand Up @@ -95,4 +98,3 @@ $(SHLIB_BUILD) $(IMPLIB): $(OBJECTS)
$(LINK.c) @LINKSHARED@ -nostartfiles -Wl,-soname=$(SHLIB) -o $@.$(MAJOR).$(MINOR) $^ -L@MAKESHLIBDIR@ -lMdsShr -lMdsIpShr $(MAKE_IMPLIB)
ln -sf $(SHLIB).$(MAJOR).$(MINOR) $@.$(MAJOR)
ln -sf $(SHLIB).$(MAJOR) $@

8 changes: 5 additions & 3 deletions camshr/QueryHighwayType.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <scsi/scsi.h>
#include <scsi/sg.h>

#include "camac_hw_iface.h"
#include "common.h"
#include "prototypes.h"

Expand Down Expand Up @@ -87,18 +88,19 @@ int QueryHighwayType(char *serial_hwy_driver)
int status = SUCCESS; // optimistic
static int channels[MAX_SCSI_BUSES]
[MAX_SCSI_IDS]; // persistant, highway types
FILE *fp, *fopen();
FILE *fp;

if (MSGLVL(FUNCTION_NAME))
printf("QHT('%s')\n", serial_hwy_driver);

host_adapter = toupper(*(serial_hwy_driver + 2)) - 'A';
scsi_id = NUMERIC(*(serial_hwy_driver + 3));

if ((fp = fopen(PROC_FILE, "r")) == NULL)
if ((fp = camac_hw_open_proc_scsi()) == NULL)
{
if (MSGLVL(ALWAYS))
fprintf(stderr, "could *NOT* open '%s' for reading\n", PROC_FILE);
fprintf(stderr, "could *NOT* open '%s' for reading\n",
camac_hw_get_proc_file());

status = FAILURE;
goto QueryHighwayType_Exit;
Expand Down
33 changes: 33 additions & 0 deletions camshr/README.sqlite-backend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# CAMSHR DB Backend Policy

`CAMSHR_DB_BACKEND` controls the CAMSHR database backend.

Default behavior:
- If `CAMSHR_DB_BACKEND` is unset or empty, CAMSHR uses the `sqlite` backend.

Supported values:
- `sqlite` / `sql` / `auto`: use sqlite backend.
- `mmap` / `legacy` / `file`: force legacy memory-mapped flat-file backend.

Notes:
- Legacy `mmap` mode is kept as a fallback compatibility path.
- When forcing legacy mode, CAMSHR prints a one-time warning to `stderr`.
- Unknown `CAMSHR_DB_BACKEND` values fall back to `sqlite` and print a one-time warning.

Testing guidance:
- Sqlite path tests:
- `camshr/testing/camshr_backend_policy_test`
- `camshr/testing/camshr_sqlite_schema_test`
- `camshr/testing/camshr_sqlite_migration_test`
- `camshr/testing/camshr_sqlite_backend_roundtrip_test`
- `camshr/testing/camshr_autoconfig_sqlite_fakeproc_test`
- Legacy fallback coverage:
- `camshr/testing/camshr_crate_state_fakehw_test` (forces `CAMSHR_DB_BACKEND=mmap`)

Native full-test note:
- In full native `ctest` runs, `tditest/testing/test-dev-py` may be skipped if
`libMitDevices` is not present in `MDSPLUS_LIBRARY_PATH`.

Hardware-less CTS note:
- `show/crate` now lists crates from the database even when live SCSI is down,
and displays cached DB status in that case.
7 changes: 4 additions & 3 deletions camshr/ScsiSystemStatus.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdio.h>
#include <string.h>

#include "camac_hw_iface.h"
#include "common.h"
#include "prototypes.h"

Expand All @@ -56,14 +57,14 @@ int ScsiSystemStatus(void)
{
char line[80], *pline;
int scsiSystemStatus = 0; // assume the worst :(
FILE *fp, *fopen();
FILE *fp;

if (MSGLVL(FUNCTION_NAME))
printf("ScsiSystemStatus()\n");

if ((fp = fopen(PROC_FILE, "r")) == NULL)
if ((fp = camac_hw_open_proc_scsi()) == NULL)
{
fprintf(stderr, "can't open '%s' for read\n", PROC_FILE);
fprintf(stderr, "can't open '%s' for read\n", camac_hw_get_proc_file());
scsiSystemStatus = 0;
goto ScsiSystemStatus_Exit;
}
Expand Down
Loading