aboutsummaryrefslogtreecommitdiff
path: root/tests/testthat
diff options
context:
space:
mode:
authorJohannes Ranke <jranke@uni-bremen.de>2023-04-15 15:35:06 +0200
committerJohannes Ranke <jranke@uni-bremen.de>2023-04-15 15:35:06 +0200
commitb0b710ee9f9bb9bbe9708676d0c5822465e02203 (patch)
tree537dcf86326ab2e03100a5defb11b264a4b72a17 /tests/testthat
parent50ea6d11f8c79218c98ee8ae56d8bdcd42cc703a (diff)
Make predefined symbols safer
We still need to create a parallel processing cluster _after_ creating a compiled model that is moved to a user defined location, at least I did not find another way to make it work. This is not a problem with parallel processing without a cluster, which is not available on Windows.
Diffstat (limited to 'tests/testthat')
-rw-r--r--tests/testthat/print_mmkin_sfo_sfo_dmta.txt0
-rw-r--r--tests/testthat/test_compiled_symbols.R54
2 files changed, 54 insertions, 0 deletions
diff --git a/tests/testthat/print_mmkin_sfo_sfo_dmta.txt b/tests/testthat/print_mmkin_sfo_sfo_dmta.txt
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/testthat/print_mmkin_sfo_sfo_dmta.txt
diff --git a/tests/testthat/test_compiled_symbols.R b/tests/testthat/test_compiled_symbols.R
new file mode 100644
index 00000000..e5f151eb
--- /dev/null
+++ b/tests/testthat/test_compiled_symbols.R
@@ -0,0 +1,54 @@
+context("Use of precompiled symbols in mkinpredict")
+
+test_that("We can safely use compiled code", {
+
+ # Generate temporary DLL
+ sfo_sfo_tmp <- mkinmod(DMTA = mkinsub("SFO", to = "M23"),
+ M23 = mkinsub("SFO"))
+
+ # Generate temporary DLL and move to user specified location
+ if (!dir.exists("test_dlls")) dir.create("test_dlls")
+ sfo_sfo_dll <- mkinmod(DMTA = mkinsub("SFO", to = "M23"),
+ M23 = mkinsub("SFO"),
+ dll_dir = "test_dlls",
+ name = "sfo_sfo",
+ unload = TRUE, overwrite = TRUE
+ )
+
+ if (Sys.info()["sysname"] != "Windows") {
+ # mclapply using forks
+ expect_known_output(
+ mmkin(list(sfo_sfo_dll), dmta_ds, cores = n_cores, quiet = TRUE),
+ "print_mmkin_sfo_sfo_dmta.txt"
+ )
+
+ # cluster describing itself as socket cluster
+ cl_fork <- parallel::makeForkCluster(n_cores)
+ expect_known_output(
+ mmkin(list(sfo_sfo_tmp), dmta_ds, cluster = cl_fork, quiet = TRUE),
+ "print_mmkin_sfo_sfo_dmta.txt"
+ )
+ expect_known_output(
+ mmkin(list(sfo_sfo_dll), dmta_ds, cluster = cl_fork, quiet = TRUE),
+ "print_mmkin_sfo_sfo_dmta.txt"
+ )
+ parallel::stopCluster(cl_fork)
+ }
+
+ # PSOCK cluster
+ cl_psock <- parallel::makePSOCKcluster(n_cores)
+ expect_known_output(
+ mmkin(list(sfo_sfo_tmp), dmta_ds, cluster = cl_psock, quiet = TRUE),
+ "print_mmkin_sfo_sfo_dmta.txt"
+ )
+ expect_known_output(
+ mmkin(list(sfo_sfo_dll), dmta_ds, cluster = cl_psock, quiet = TRUE),
+ "print_mmkin_sfo_sfo_dmta.txt"
+ )
+ parallel::stopCluster(cl_psock)
+
+ # Clean up
+ expect_true(file.remove("test_dlls/sfo_sfo.so"))
+ expect_true(file.remove("test_dlls"))
+})
+

Contact - Imprint