diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index e6882827..4655cdde 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -41,7 +41,7 @@ jobs: - name: Run other tests working-directory: tests run: | - tests=("command-line-options" "data-rep" "i18n_sjis" "jp-compat" "run" "syntax" "cobj-idx" "indexed-lock" "misc") + tests=("command-line-options" "data-rep" "i18n_sjis" "jp-compat" "run" "syntax" "cobj-idx" "file-lock" "misc") for test in "${tests[@]}"; do ./"$test" || true done diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 2b8cd063..b50a9379 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -54,7 +54,7 @@ jobs: - "syntax" - "cobj-idx" - "misc" - - "indexed-lock" + - "file-lock" os: ["ubuntu:24.04", "almalinux:9", "amazonlinux:2023"] uses: ./.github/workflows/test-other.yml with: @@ -75,7 +75,7 @@ jobs: - "run" - "syntax" - "cobj-idx" - - "indexed-lock" + - "file-lock" #- "misc" os: ["ubuntu:24.04", "almalinux:9", "amazonlinux:2023"] uses: ./.github/workflows/test-other.yml diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index a1eefb61..18d39930 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -58,7 +58,7 @@ jobs: - "run" - "syntax" - "cobj-idx" - - "indexed-lock" + - "file-lock" - "misc" os: ["ubuntu:24.04"] uses: ./.github/workflows/test-other.yml @@ -80,7 +80,7 @@ jobs: - "run" - "syntax" - "cobj-idx" - - "indexed-lock" + - "file-lock" #- "misc" os: ["ubuntu:24.04"] uses: ./.github/workflows/test-other.yml diff --git a/.gitignore b/.gitignore index 9e4d9bb1..cef26e9c 100644 --- a/.gitignore +++ b/.gitignore @@ -54,7 +54,7 @@ tests/jp-compat tests/cobj-idx tests/misc tests/run -tests/indexed-lock +tests/file-lock tests/*.log tests/syntax tests/cobol85/*/*.class diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java index 1b6c65a4..f3747fcf 100755 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolFile.java @@ -1210,13 +1210,13 @@ public int open_(String filename, int mode, int sharing) throws IOException { FileLock fl = null; if (!filename.startsWith("/dev/")) { try { - boolean lockFlag; + boolean isSharedLock; if (sharing != 0 || mode == COB_OPEN_OUTPUT) { - lockFlag = false; + isSharedLock = false; } else { - lockFlag = true; + isSharedLock = true; } - fl = fp.tryLock(0L, Long.MAX_VALUE, lockFlag); + fl = fp.tryLock(0L, Long.MAX_VALUE, isSharedLock); } catch (NonWritableChannelException e) { fp.close(); return EBADF; diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolRelativeFile.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolRelativeFile.java index 72ee7ff8..a49f5b6f 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolRelativeFile.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/CobolRelativeFile.java @@ -22,7 +22,6 @@ import java.nio.ByteBuffer; import java.nio.channels.*; import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.Paths; import jp.osscons.opensourcecobol.libcobj.data.AbstractCobolField; @@ -140,12 +139,7 @@ public int open_(String filename, int mode, int sharing) throws IOException { this.fp.seek(0); break; case COB_OPEN_OUTPUT: - Path path = Paths.get(filename); - if (Files.exists(path)) { - Files.delete(path); - } this.fp = new RandomAccessFile(this.assign.fieldToString(), "rw"); - this.fp.seek(0); break; case COB_OPEN_I_O: this.fp = new RandomAccessFile(this.assign.fieldToString(), "rw"); @@ -175,13 +169,13 @@ public int open_(String filename, int mode, int sharing) throws IOException { FileLock fl = null; if (!filename.startsWith("/dev/")) { try { - boolean lockFlag; + boolean isSharedLock; if (sharing != 0 || mode == COB_OPEN_OUTPUT) { - lockFlag = false; + isSharedLock = false; } else { - lockFlag = true; + isSharedLock = true; } - fl = ch.tryLock(0L, Long.MAX_VALUE, lockFlag); + fl = ch.tryLock(0L, Long.MAX_VALUE, isSharedLock); } catch (NonWritableChannelException e) { this.fp.close(); return EBADF; @@ -198,6 +192,11 @@ public int open_(String filename, int mode, int sharing) throws IOException { } } + if(mode == COB_OPEN_OUTPUT) { + this.fp.setLength(0); + this.fp.seek(0); + } + this.file.setRandomAccessFile(this.fp, fl); if ((this.flag_select_features & COB_SELECT_LINAGE) != 0) { if (this.file_linage_check()) { diff --git a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/FileIO.java b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/FileIO.java index 8ca82b46..b3634358 100644 --- a/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/FileIO.java +++ b/libcobj/app/src/main/java/jp/osscons/opensourcecobol/libcobj/file/FileIO.java @@ -90,6 +90,7 @@ void setRandomAccessFile(RandomAccessFile ra, FileLock fl) { this.useStdOut = false; this.useStdIn = false; this.fc = ra.getChannel(); + this.fl = fl; } /** diff --git a/tests/.gitignore b/tests/.gitignore index fa865cd1..2d979a6a 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -6,5 +6,5 @@ run~ syntax~ command-line-options~ cobj-idx~ -indexed-lock~ +file-lock~ *.dir diff --git a/tests/Makefile.am b/tests/Makefile.am index 2c68394d..c9653eba 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -30,7 +30,7 @@ TESTS = syntax \ jp-compat \ command-line-options \ cobj-idx \ - indexed-lock \ + file-lock \ misc else TESTS = syntax \ @@ -42,7 +42,7 @@ TESTS = syntax \ jp-compat \ command-line-options \ cobj-idx \ - indexed-lock \ + file-lock \ misc endif @@ -209,18 +209,18 @@ cobj_idx_DEPENDENCIES = \ cobj-idx.src/misc.at indexed_lock_DEPENDENCIES = \ - indexed-lock.at \ - indexed-lock.src/file-lock.at \ - indexed-lock.src/access-same-record.at \ - indexed-lock.src/access-different-record.at \ - indexed-lock.src/input-mode.at \ - indexed-lock.src/same-process.at \ - indexed-lock.src/open-start-write-rewrite.at \ - indexed-lock.src/release-lock.at \ - indexed-lock.src/open-input.at \ - indexed-lock.src/lock-mode-clause.at \ - indexed-lock.src/old-file.at \ - indexed-lock.src/lock-mode-automatic.at + file-lock.at \ + file-lock.src/lock-file.at \ + file-lock.src/access-same-record.at \ + file-lock.src/access-different-record.at \ + file-lock.src/input-mode.at \ + file-lock.src/same-process.at \ + file-lock.src/open-start-write-rewrite.at \ + file-lock.src/release-lock.at \ + file-lock.src/open-input.at \ + file-lock.src/lock-mode-clause.at \ + file-lock.src/old-file.at \ + file-lock.src/lock-mode-automatic.at misc_DEPENDENCIES = \ misc.src/signed-comp3.at \ @@ -305,5 +305,5 @@ $(srcdir)/i18n_sjis: $(i18n_sjis_DEPENDENCIES) $(srcdir)/jp-compat: $(jp_compat_DEPENDENCIES) $(srcdir)/command-line-options: $(command_line_options_DEPENDENCIES) $(srcdir)/cobj-idx: $(cobj_idx_DEPENDENCIES) -$(srcdir)/indexed-lock: $(indexed_lock_DEPENDENCIES) +$(srcdir)/file-lock: $(indexed_lock_DEPENDENCIES) $(srcdir)/misc: $(misc_DEPENDENCIES) diff --git a/tests/Makefile.in b/tests/Makefile.in index 923c4437..9075bfd1 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -570,7 +570,7 @@ SUBDIRS = cobol85 @I18N_UTF8_FALSE@ jp-compat \ @I18N_UTF8_FALSE@ command-line-options \ @I18N_UTF8_FALSE@ cobj-idx \ -@I18N_UTF8_FALSE@ indexed-lock \ +@I18N_UTF8_FALSE@ file-lock \ @I18N_UTF8_FALSE@ misc @I18N_UTF8_TRUE@TESTS = syntax \ @@ -582,7 +582,7 @@ SUBDIRS = cobol85 @I18N_UTF8_TRUE@ jp-compat \ @I18N_UTF8_TRUE@ command-line-options \ @I18N_UTF8_TRUE@ cobj-idx \ -@I18N_UTF8_TRUE@ indexed-lock \ +@I18N_UTF8_TRUE@ file-lock \ @I18N_UTF8_TRUE@ misc syntax_DEPENDENCIES = \ @@ -748,18 +748,18 @@ cobj_idx_DEPENDENCIES = \ cobj-idx.src/misc.at indexed_lock_DEPENDENCIES = \ - indexed-lock.at \ - indexed-lock.src/file-lock.at \ - indexed-lock.src/access-same-record.at \ - indexed-lock.src/access-different-record.at \ - indexed-lock.src/input-mode.at \ - indexed-lock.src/same-process.at \ - indexed-lock.src/open-start-write-rewrite.at \ - indexed-lock.src/release-lock.at \ - indexed-lock.src/open-input.at \ - indexed-lock.src/lock-mode-clause.at \ - indexed-lock.src/old-file.at \ - indexed-lock.src/lock-mode-automatic.at + file-lock.at \ + file-lock.src/lock-file.at \ + file-lock.src/access-same-record.at \ + file-lock.src/access-different-record.at \ + file-lock.src/input-mode.at \ + file-lock.src/same-process.at \ + file-lock.src/open-start-write-rewrite.at \ + file-lock.src/release-lock.at \ + file-lock.src/open-input.at \ + file-lock.src/lock-mode-clause.at \ + file-lock.src/old-file.at \ + file-lock.src/lock-mode-automatic.at misc_DEPENDENCIES = \ misc.src/signed-comp3.at \ @@ -1159,9 +1159,9 @@ cobj-idx.log: cobj-idx --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) -indexed-lock.log: indexed-lock - @p='indexed-lock'; \ - b='indexed-lock'; \ +file-lock.log: file-lock + @p='file-lock'; \ + b='file-lock'; \ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ @@ -1407,7 +1407,7 @@ $(srcdir)/i18n_sjis: $(i18n_sjis_DEPENDENCIES) $(srcdir)/jp-compat: $(jp_compat_DEPENDENCIES) $(srcdir)/command-line-options: $(command_line_options_DEPENDENCIES) $(srcdir)/cobj-idx: $(cobj_idx_DEPENDENCIES) -$(srcdir)/indexed-lock: $(indexed_lock_DEPENDENCIES) +$(srcdir)/file-lock: $(indexed_lock_DEPENDENCIES) $(srcdir)/misc: $(misc_DEPENDENCIES) # Tell versions [3.59,3.63) of GNU make to not export all variables. diff --git a/tests/indexed-lock.at b/tests/file-lock.at similarity index 86% rename from tests/indexed-lock.at rename to tests/file-lock.at index 79c9b197..24985fce 100644 --- a/tests/indexed-lock.at +++ b/tests/file-lock.at @@ -1,6 +1,6 @@ -AT_INIT([indexed-lock]) +AT_INIT([file-lock]) -m4_include([file-lock.at]) +m4_include([lock-file.at]) m4_include([access-same-record.at]) m4_include([access-different-record.at]) m4_include([input-mode.at]) diff --git a/tests/indexed-lock.src/access-different-record.at b/tests/file-lock.src/access-different-record.at similarity index 99% rename from tests/indexed-lock.src/access-different-record.at rename to tests/file-lock.src/access-different-record.at index 00d8e40b..52fccb2a 100644 --- a/tests/indexed-lock.src/access-different-record.at +++ b/tests/file-lock.src/access-different-record.at @@ -231,8 +231,8 @@ run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_DELETE" ]) -AT_CHECK([cp ../../indexed-lock.src/module-sync/wait.java .]) -AT_CHECK([cp ../../indexed-lock.src/module-sync/setValue.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .]) AT_DATA([prog1.template.cbl], [ IDENTIFICATION DIVISION. diff --git a/tests/indexed-lock.src/access-same-record.at b/tests/file-lock.src/access-same-record.at similarity index 99% rename from tests/indexed-lock.src/access-same-record.at rename to tests/file-lock.src/access-same-record.at index b3d942cc..21e3414e 100644 --- a/tests/indexed-lock.src/access-same-record.at +++ b/tests/file-lock.src/access-same-record.at @@ -206,8 +206,8 @@ run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_DELETE" ]) -AT_CHECK([cp ../../indexed-lock.src/module-sync/wait.java .]) -AT_CHECK([cp ../../indexed-lock.src/module-sync/setValue.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .]) AT_DATA([prog1.template.cbl], [ IDENTIFICATION DIVISION. diff --git a/tests/indexed-lock.src/indexed-file/old_indexed_file.dat b/tests/file-lock.src/indexed-file/old_indexed_file.dat similarity index 100% rename from tests/indexed-lock.src/indexed-file/old_indexed_file.dat rename to tests/file-lock.src/indexed-file/old_indexed_file.dat diff --git a/tests/indexed-lock.src/input-mode.at b/tests/file-lock.src/input-mode.at similarity index 99% rename from tests/indexed-lock.src/input-mode.at rename to tests/file-lock.src/input-mode.at index 16df00d9..0b6ae385 100644 --- a/tests/indexed-lock.src/input-mode.at +++ b/tests/file-lock.src/input-mode.at @@ -183,8 +183,8 @@ run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_READ_NEXT_RECORD ]) -AT_CHECK([cp ../../indexed-lock.src/module-sync/wait.java .]) -AT_CHECK([cp ../../indexed-lock.src/module-sync/setValue.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .]) AT_DATA([prog1.template.cbl], [ IDENTIFICATION DIVISION. diff --git a/tests/file-lock.src/lock-file.at b/tests/file-lock.src/lock-file.at new file mode 100644 index 00000000..bfe47620 --- /dev/null +++ b/tests/file-lock.src/lock-file.at @@ -0,0 +1,543 @@ +AT_SETUP([File locking of indexed files]) +AT_DATA([make_indexed_file.cbl],[ + identification division. + program-id. make_indexed_file@@id@@. + + environment division. + input-output section. + + file-control. + select indexed-file + assign to external "indexed@@id@@.dat" + organization is indexed + record key is rec-key + file status is indexed-file-status. + + data division. + file section. + fd indexed-file. + 01 dup-record. + 05 rec-key pic x(5). + 05 rec-value pic x(5). + working-storage section. + 01 indexed-file-status pic 99. + procedure division. + main-procedure. + + open output indexed-file. + close indexed-file. +]) + +AT_DATA([prog1.cbl], [ + identification division. + program-id. prog1@@id@@. + + environment division. + input-output section. + + file-control. + select indexed-file + assign to "indexed@@id@@.dat" + organization is indexed + record key is rec-key + file status is indexed-file-status. + + select shared-file1 + assign to "shared1@@id@@.dat" + organization is sequential + file status is shared-file1-status. + + select shared-file2 + assign to "shared2@@id@@.dat" + organization is sequential + file status is shared-file2-status. + + data division. + file section. + fd indexed-file. + 01 dup-record. + 05 rec-key pic x(5). + 05 rec-value pic x(5). + fd shared-file1. + 01 shared-record1 pic x(10). + fd shared-file2. + 01 shared-record2 pic x(10). + working-storage section. + 01 indexed-file-status pic 99. + 01 shared-file1-status pic 99. + 01 shared-file2-status pic 99. + procedure division. + main-procedure. + + * open the indexed file before the other process does. + open @@open_mode@@ indexed-file. + + * Notify the other process that + * this process opened the indexed file. + open output shared-file1. + close shared-file1. + + * Wait for the other process to finish. + call "C$SLEEP" using 1. + perform forever + open input shared-file2 + if shared-file2-status = 0 + exit perform + end-if + close shared-file2 + call "C$SLEEP" using 1 + end-perform. + close shared-file2. + + * Close the indexed file after the other process has finished. + close indexed-file. +]) + +AT_DATA([prog2.cbl], [ + identification division. + program-id. prog2@@id@@. + + environment division. + input-output section. + + file-control. + select indexed-file + assign to "indexed@@id@@.dat" + organization is indexed + record key is rec-key + file status is indexed-file-status. + + select shared-file1 + assign to "shared1@@id@@.dat" + organization is sequential + file status is shared-file1-status. + + select shared-file2 + assign to "shared2@@id@@.dat" + organization is sequential + file status is shared-file2-status. + + data division. + file section. + fd indexed-file. + 01 dup-record. + 05 rec-key pic x(5). + 05 rec-value pic x(5). + fd shared-file1. + 01 shared-record1 pic x(10). + fd shared-file2. + 01 shared-record2 pic x(10). + working-storage section. + 01 indexed-file-status pic 99. + 01 shared-file1-status pic 99. + 01 shared-file2-status pic 99. + procedure division. + main-procedure. + + * Wait for the other process to open the indexed file. + call "C$SLEEP" using 1. + perform forever + open input shared-file1 + if shared-file1-status = 0 + close shared-file1 + exit perform + end-if + close shared-file1 + call "C$SLEEP" using 1 + end-perform. + + * Open the indexed file that another process has already opened. + open @@open_mode@@ indexed-file. + display indexed-file-status. + close indexed-file. + + * Notify the other process that + * this process finished. + open output shared-file2. + close shared-file2. +]) + +AT_DATA([run.sh], [ +#!/bin/bash + +function run_test() { + SEQ_NUMBER=$1 + OPEN_MODE_1=$2 + OPEN_MODE_2=$3 + EXPECTED_EXIT_CODE=$4 + + rm -f *.dat + + TEST_ID="$(echo "${OPEN_MODE_1}_${OPEN_MODE_2}" | sed 's/-/_/g')" + + PROGRAM_NAME_1="prog1${TEST_ID}" + PROGRAM_NAME_2="prog2${TEST_ID}" + + cat "prog1.cbl" | + sed "s/@@id@@/${TEST_ID}/g" | + sed "s/@@open_mode@@/${OPEN_MODE_1}/g" \ + > ${PROGRAM_NAME_1}.cbl + + cat "prog2.cbl" | + sed "s/@@id@@/${TEST_ID}/g" | + sed "s/@@open_mode@@/${OPEN_MODE_2}/g" \ + > ${PROGRAM_NAME_2}.cbl + + cat "make_indexed_file.cbl" | + sed "s/@@id@@/${TEST_ID}/g" \ + > make_indexed_file${TEST_ID}.cbl + + cobj ${PROGRAM_NAME_1}.cbl ${PROGRAM_NAME_2}.cbl make_indexed_file${TEST_ID}.cbl + + java -Xlog:perf+memops=off make_indexed_file${TEST_ID} + + java -Xlog:perf+memops=off $PROGRAM_NAME_1 & + PID1=$! + + java -Xlog:perf+memops=off $PROGRAM_NAME_2 > ${TEST_ID}.log & + PID2=$! + + wait $PID1 $PID2 + if test "$(cat ${TEST_ID}.log)" != "${EXPECTED_EXIT_CODE}"; then + echo "<${SEQ_NUMBER}> Test ${TEST_ID} failed. Expected exit code: ${EXPECTED_EXIT_CODE}, got: $(cat ${TEST_ID}.log)" \ + exit 1 + fi +} + +################################### + +run_test 00 INPUT INPUT 00 +run_test 01 INPUT OUTPUT 61 +run_test 02 INPUT I-O 00 +run_test 03 INPUT EXTEND 00 +run_test 04 OUTPUT INPUT 61 +run_test 05 OUTPUT OUTPUT 61 +run_test 06 OUTPUT I-O 61 +run_test 07 OUTPUT EXTEND 61 +run_test 08 I-O INPUT 00 +run_test 09 I-O OUTPUT 61 +run_test 10 I-O I-O 00 +run_test 11 I-O EXTEND 00 +run_test 12 EXTEND INPUT 00 +run_test 13 EXTEND OUTPUT 61 +run_test 14 EXTEND I-O 00 +run_test 15 EXTEND EXTEND 00 +]) + +AT_CHECK([bash run.sh]) +AT_CLEANUP + +AT_SETUP([File locking of SEQUENTIAL, LINE SEQUENTIAL and RELATIVE files]) +AT_DATA([prog1-template.cbl],[ + identification division. + program-id. + prog1_@@id@@. + environment division. + input-output section. + + file-control. + select f + assign to "file.dat" + organization is @@file_organization@@ + file status is f-status. + + select shared-file1 + assign to "shared1.dat" + organization is sequential + file status is shared-file1-status. + + select shared-file2 + assign to "shared2.dat" + organization is sequential + file status is shared-file2-status. + + data division. + file section. + fd f. + 01 f-record. + 05 rec-key pic x(5). + 05 rec-value pic x(5). + fd shared-file1. + 01 shared-record1 pic x(10). + fd shared-file2. + 01 shared-record2 pic x(10). + working-storage section. + 01 f-status pic 99. + 01 shared-file1-status pic 99. + 01 shared-file2-status pic 99. + procedure division. + main-procedure. + + * create the target file. + open output f. + close f. + + * open the target file before the other process does. + open @@open_mode@@ f. + + * Notify the other process that + * this process opened the target file. + open output shared-file1. + close shared-file1. + + * Wait for the other process to finish. + *call "C$SLEEP" using 1. + perform forever + open input shared-file2 + if shared-file2-status = 0 + exit perform + end-if + close shared-file2 + * call "C$SLEEP" using 1 + end-perform. + close shared-file2. + + * Close the target file after the other process has finished. + close f. +]) + +AT_DATA([prog2-template.cbl],[ + identification division. + program-id. + prog2_@@id@@. + environment division. + input-output section. + + file-control. + select f + assign to "file.dat" + organization is @@file_organization@@ + file status is f-status. + + select shared-file1 + assign to "shared1.dat" + organization is sequential + file status is shared-file1-status. + + select shared-file2 + assign to "shared2.dat" + organization is sequential + file status is shared-file2-status. + + data division. + file section. + fd f. + 01 f-record. + 05 rec-key pic x(5). + 05 rec-value pic x(5). + fd shared-file1. + 01 shared-record1 pic x(10). + fd shared-file2. + 01 shared-record2 pic x(10). + working-storage section. + 01 f-status pic 99. + 01 shared-file1-status pic 99. + 01 shared-file2-status pic 99. + procedure division. + main-procedure. + + * Wait for the other process to open the indexed file. + *call "C$SLEEP" using 1. + perform forever + open input shared-file1 + if shared-file1-status = 0 + close shared-file1 + exit perform + end-if + close shared-file1 + * call "C$SLEEP" using 1 + end-perform. + + * Open the target file that another process has already opened. + open @@open_mode@@ f. + display f-status. + close f. + + * Notify the other process that + * this process finished. + open output shared-file2. + close shared-file2. +]) + +AT_DATA([run.sh], [ +#!/bin/bash + +set -e + +COMPILER="cobj" +RUNNER="java -Xlog:perf+memops=off" + +rm -f file.dat shared1.dat shared2.dat + +function compile_all() { + for ORGANIZATION in "sequential" "line sequential" "relative"; do + for OPEN_MODE_1 in "INPUT" "OUTPUT" "I-O" "EXTEND"; do + for OPEN_MODE_2 in "INPUT" "OUTPUT" "I-O" "EXTEND"; do + ID=$(echo "${ORGANIZATION:0:1}_${OPEN_MODE_1}_${OPEN_MODE_2}" | sed 's/-/_/g') + PROGRAM_ID_1="prog1_${ID}" + PROGRAM_ID_2="prog2_${ID}" + PROGRAM1_FILE="${PROGRAM_ID_1}.cbl" + PROGRAM2_FILE="${PROGRAM_ID_2}.cbl" + + cat prog1-template.cbl | + sed "s/@@id@@/${ID}/g; s/@@file_organization@@/${ORGANIZATION}/g; s/@@open_mode@@/${OPEN_MODE_1}/g" \ + > "${PROGRAM1_FILE}" + cat prog2-template.cbl | + sed "s/@@id@@/${ID}/g; s/@@file_organization@@/${ORGANIZATION}/g; s/@@open_mode@@/${OPEN_MODE_2}/g" \ + > "${PROGRAM2_FILE}" + + "${COMPILER}" "${PROGRAM1_FILE}" "${PROGRAM2_FILE}" + done + done + done +} + +function run_test() { + ORGANIZATION="$1" + OPEN_MODE_1="$2" + OPEN_MODE_2="$3" + + ID=$(echo "${ORGANIZATION:0:1}_${OPEN_MODE_1}_${OPEN_MODE_2}" | sed 's/-/_/g') + PROGRAM_ID_1="prog1_${ID}" + PROGRAM_ID_2="prog2_${ID}" + PROGRAM1_FILE="${PROGRAM_ID_1}.cbl" + PROGRAM2_FILE="${PROGRAM_ID_2}.cbl" + PROGRAM1_LOG="${PROGRAM_ID_1}.log" + PROGRAM2_LOG="${PROGRAM_ID_2}.log" + + rm -f file.dat shared1.dat shared2.dat + + cat prog1-template.cbl | + sed "s/@@id@@/${ID}/g; s/@@file_organization@@/${ORGANIZATION}/g; s/@@open_mode@@/${OPEN_MODE_1}/g" \ + > "${PROGRAM1_FILE}" + cat prog2-template.cbl | + sed "s/@@id@@/${ID}/g; s/@@file_organization@@/${ORGANIZATION}/g; s/@@open_mode@@/${OPEN_MODE_2}/g" \ + > "${PROGRAM2_FILE}" + + "${COMPILER}" "${PROGRAM1_FILE}" "${PROGRAM2_FILE}" + + ${RUNNER} "${PROGRAM_ID_1}"& + PID1=$! + ${RUNNER} "${PROGRAM_ID_2}" > "${PROGRAM2_LOG}" & + PID2=$! + wait $PID1 $PID2 + + echo "${ORGANIZATION} - ${OPEN_MODE_1} & ${OPEN_MODE_2} - $(cat "${PROGRAM2_LOG}")" +} + +# First, compile all combinations +compile_all + +# Then, run a specific test case +run_test "sequential" "INPUT" "INPUT" +run_test "sequential" "INPUT" "OUTPUT" +run_test "sequential" "INPUT" "I-O" +run_test "sequential" "INPUT" "EXTEND" + +run_test "sequential" "OUTPUT" "INPUT" +run_test "sequential" "OUTPUT" "OUTPUT" +run_test "sequential" "OUTPUT" "I-O" +run_test "sequential" "OUTPUT" "EXTEND" + +run_test "sequential" "I-O" "INPUT" +run_test "sequential" "I-O" "OUTPUT" +run_test "sequential" "I-O" "I-O" +run_test "sequential" "I-O" "EXTEND" + +run_test "sequential" "EXTEND" "INPUT" +run_test "sequential" "EXTEND" "OUTPUT" +run_test "sequential" "EXTEND" "I-O" +run_test "sequential" "EXTEND" "EXTEND" + +run_test "line sequential" "INPUT" "INPUT" +run_test "line sequential" "INPUT" "OUTPUT" +run_test "line sequential" "INPUT" "I-O" +run_test "line sequential" "INPUT" "EXTEND" + +run_test "line sequential" "OUTPUT" "INPUT" +run_test "line sequential" "OUTPUT" "OUTPUT" +run_test "line sequential" "OUTPUT" "I-O" +run_test "line sequential" "OUTPUT" "EXTEND" + +run_test "line sequential" "I-O" "INPUT" +run_test "line sequential" "I-O" "OUTPUT" +run_test "line sequential" "I-O" "I-O" +run_test "line sequential" "I-O" "EXTEND" + +run_test "line sequential" "EXTEND" "INPUT" +run_test "line sequential" "EXTEND" "OUTPUT" +run_test "line sequential" "EXTEND" "I-O" +run_test "line sequential" "EXTEND" "EXTEND" + +run_test "relative" "INPUT" "INPUT" +run_test "relative" "INPUT" "OUTPUT" +run_test "relative" "INPUT" "I-O" +run_test "relative" "INPUT" "EXTEND" + +run_test "relative" "OUTPUT" "INPUT" +run_test "relative" "OUTPUT" "OUTPUT" +run_test "relative" "OUTPUT" "I-O" +run_test "relative" "OUTPUT" "EXTEND" + +run_test "relative" "I-O" "INPUT" +run_test "relative" "I-O" "OUTPUT" +run_test "relative" "I-O" "I-O" +run_test "relative" "I-O" "EXTEND" + +run_test "relative" "EXTEND" "INPUT" +run_test "relative" "EXTEND" "OUTPUT" +run_test "relative" "EXTEND" "I-O" +run_test "relative" "EXTEND" "EXTEND" +]) + +AT_CHECK([bash run.sh], [0], +[sequential - INPUT & INPUT - 00 +sequential - INPUT & OUTPUT - 61 +sequential - INPUT & I-O - 61 +sequential - INPUT & EXTEND - 61 +sequential - OUTPUT & INPUT - 61 +sequential - OUTPUT & OUTPUT - 61 +sequential - OUTPUT & I-O - 61 +sequential - OUTPUT & EXTEND - 61 +sequential - I-O & INPUT - 61 +sequential - I-O & OUTPUT - 61 +sequential - I-O & I-O - 61 +sequential - I-O & EXTEND - 61 +sequential - EXTEND & INPUT - 61 +sequential - EXTEND & OUTPUT - 61 +sequential - EXTEND & I-O - 61 +sequential - EXTEND & EXTEND - 61 +line sequential - INPUT & INPUT - 00 +line sequential - INPUT & OUTPUT - 61 +line sequential - INPUT & I-O - 61 +line sequential - INPUT & EXTEND - 61 +line sequential - OUTPUT & INPUT - 61 +line sequential - OUTPUT & OUTPUT - 61 +line sequential - OUTPUT & I-O - 61 +line sequential - OUTPUT & EXTEND - 61 +line sequential - I-O & INPUT - 61 +line sequential - I-O & OUTPUT - 61 +line sequential - I-O & I-O - 61 +line sequential - I-O & EXTEND - 61 +line sequential - EXTEND & INPUT - 61 +line sequential - EXTEND & OUTPUT - 61 +line sequential - EXTEND & I-O - 61 +line sequential - EXTEND & EXTEND - 61 +relative - INPUT & INPUT - 00 +relative - INPUT & OUTPUT - 61 +relative - INPUT & I-O - 61 +relative - INPUT & EXTEND - 61 +relative - OUTPUT & INPUT - 61 +relative - OUTPUT & OUTPUT - 61 +relative - OUTPUT & I-O - 61 +relative - OUTPUT & EXTEND - 61 +relative - I-O & INPUT - 61 +relative - I-O & OUTPUT - 61 +relative - I-O & I-O - 61 +relative - I-O & EXTEND - 61 +relative - EXTEND & INPUT - 61 +relative - EXTEND & OUTPUT - 61 +relative - EXTEND & I-O - 61 +relative - EXTEND & EXTEND - 61 +]) +AT_CLEANUP \ No newline at end of file diff --git a/tests/indexed-lock.src/lock-mode-automatic.at b/tests/file-lock.src/lock-mode-automatic.at similarity index 99% rename from tests/indexed-lock.src/lock-mode-automatic.at rename to tests/file-lock.src/lock-mode-automatic.at index bb671510..f96c9eff 100644 --- a/tests/indexed-lock.src/lock-mode-automatic.at +++ b/tests/file-lock.src/lock-mode-automatic.at @@ -213,8 +213,8 @@ run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_DELETE" ]) -AT_CHECK([cp ../../indexed-lock.src/module-sync/wait.java .]) -AT_CHECK([cp ../../indexed-lock.src/module-sync/setValue.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .]) AT_DATA([prog1.template.cbl], [ IDENTIFICATION DIVISION. diff --git a/tests/indexed-lock.src/lock-mode-clause.at b/tests/file-lock.src/lock-mode-clause.at similarity index 99% rename from tests/indexed-lock.src/lock-mode-clause.at rename to tests/file-lock.src/lock-mode-clause.at index e622ac34..0bb43e5e 100644 --- a/tests/indexed-lock.src/lock-mode-clause.at +++ b/tests/file-lock.src/lock-mode-clause.at @@ -290,8 +290,8 @@ run_test "$OPERATION_READ_NEXT_RECORD_WITH_NO_LOCK" "$OPERATION_DELETE" ]) -AT_CHECK([cp ../../indexed-lock.src/module-sync/wait.java .]) -AT_CHECK([cp ../../indexed-lock.src/module-sync/setValue.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .]) AT_DATA([prog1.template.cbl], [ IDENTIFICATION DIVISION. diff --git a/tests/indexed-lock.src/module-sync/setValue.java b/tests/file-lock.src/module-sync/setValue.java similarity index 100% rename from tests/indexed-lock.src/module-sync/setValue.java rename to tests/file-lock.src/module-sync/setValue.java diff --git a/tests/indexed-lock.src/module-sync/wait.java b/tests/file-lock.src/module-sync/wait.java similarity index 100% rename from tests/indexed-lock.src/module-sync/wait.java rename to tests/file-lock.src/module-sync/wait.java diff --git a/tests/indexed-lock.src/old-file.at b/tests/file-lock.src/old-file.at similarity index 93% rename from tests/indexed-lock.src/old-file.at rename to tests/file-lock.src/old-file.at index 680c52a5..8e2ab9e3 100644 --- a/tests/indexed-lock.src/old-file.at +++ b/tests/file-lock.src/old-file.at @@ -43,7 +43,7 @@ AT_DATA([open_file_status.at], [ ]) AT_CHECK([${COBJ} open_file_status.at]) -AT_CHECK([cp ../../indexed-lock.src/indexed-file/old_indexed_file.dat indexed_file.dat]) +AT_CHECK([cp ../../file-lock.src/indexed-file/old_indexed_file.dat indexed_file.dat]) AT_CHECK([java -Xlog:perf+memops=off open_file_status], [0], [92 92 diff --git a/tests/indexed-lock.src/open-input.at b/tests/file-lock.src/open-input.at similarity index 98% rename from tests/indexed-lock.src/open-input.at rename to tests/file-lock.src/open-input.at index f6c1b631..65941cb2 100644 --- a/tests/indexed-lock.src/open-input.at +++ b/tests/file-lock.src/open-input.at @@ -165,8 +165,8 @@ run_test "$OPERATION_READ_NEXT_RECORD_WITH_LOCK" "$OPERATION_DELETE" ]) -AT_CHECK([cp ../../indexed-lock.src/module-sync/wait.java .]) -AT_CHECK([cp ../../indexed-lock.src/module-sync/setValue.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .]) AT_DATA([prog1.template.cbl], [ IDENTIFICATION DIVISION. diff --git a/tests/indexed-lock.src/open-start-write-rewrite.at b/tests/file-lock.src/open-start-write-rewrite.at similarity index 99% rename from tests/indexed-lock.src/open-start-write-rewrite.at rename to tests/file-lock.src/open-start-write-rewrite.at index 7022b91e..aa5e9b16 100644 --- a/tests/indexed-lock.src/open-start-write-rewrite.at +++ b/tests/file-lock.src/open-start-write-rewrite.at @@ -196,8 +196,8 @@ run_test "$OPERATION_REWRITE" "$OPERATION_DELETE" "00" "0 ]) -AT_CHECK([cp ../../indexed-lock.src/module-sync/wait.java .]) -AT_CHECK([cp ../../indexed-lock.src/module-sync/setValue.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .]) AT_DATA([prog1.template.cbl], [ IDENTIFICATION DIVISION. diff --git a/tests/indexed-lock.src/release-lock.at b/tests/file-lock.src/release-lock.at similarity index 97% rename from tests/indexed-lock.src/release-lock.at rename to tests/file-lock.src/release-lock.at index 6e477e2e..cefde4f5 100644 --- a/tests/indexed-lock.src/release-lock.at +++ b/tests/file-lock.src/release-lock.at @@ -174,8 +174,8 @@ run_test "$OPERATION_CLOSE" "$OPERATION_REWRITE" "00" " ]) -AT_CHECK([cp ../../indexed-lock.src/module-sync/wait.java .]) -AT_CHECK([cp ../../indexed-lock.src/module-sync/setValue.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .]) AT_DATA([prog1.template.cbl], [ IDENTIFICATION DIVISION. @@ -442,8 +442,8 @@ AT_DATA([run.sh], [ wait $PID1 $PID2 ]) -AT_CHECK([cp ../../indexed-lock.src/module-sync/wait.java .]) -AT_CHECK([cp ../../indexed-lock.src/module-sync/setValue.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .]) AT_CHECK([cobj p1.cbl p2.cbl]) AT_CHECK([javac wait.java setValue.java]) @@ -577,8 +577,8 @@ AT_DATA([run.sh], [ wait $PID1 $PID2 ]) -AT_CHECK([cp ../../indexed-lock.src/module-sync/wait.java .]) -AT_CHECK([cp ../../indexed-lock.src/module-sync/setValue.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/wait.java .]) +AT_CHECK([cp ../../file-lock.src/module-sync/setValue.java .]) AT_CHECK([cobj p1.cbl p2.cbl]) AT_CHECK([javac wait.java setValue.java]) diff --git a/tests/indexed-lock.src/same-process.at b/tests/file-lock.src/same-process.at similarity index 100% rename from tests/indexed-lock.src/same-process.at rename to tests/file-lock.src/same-process.at diff --git a/tests/indexed-lock.src/file-lock.at b/tests/indexed-lock.src/file-lock.at deleted file mode 100644 index 68032cf1..00000000 --- a/tests/indexed-lock.src/file-lock.at +++ /dev/null @@ -1,228 +0,0 @@ -AT_SETUP([File locking of indexed files]) -AT_DATA([make_indexed_file.cbl],[ - identification division. - program-id. make_indexed_file@@id@@. - - environment division. - input-output section. - - file-control. - select indexed-file - assign to external "indexed@@id@@.dat" - organization is indexed - record key is rec-key - file status is indexed-file-status. - - data division. - file section. - fd indexed-file. - 01 dup-record. - 05 rec-key pic x(5). - 05 rec-value pic x(5). - working-storage section. - 01 indexed-file-status pic 99. - procedure division. - main-procedure. - - open output indexed-file. - close indexed-file. -]) - -AT_DATA([prog1.cbl], [ - identification division. - program-id. prog1@@id@@. - - environment division. - input-output section. - - file-control. - select indexed-file - assign to "indexed@@id@@.dat" - organization is indexed - record key is rec-key - file status is indexed-file-status. - - select shared-file1 - assign to "shared1@@id@@.dat" - organization is sequential - file status is shared-file1-status. - - select shared-file2 - assign to "shared2@@id@@.dat" - organization is sequential - file status is shared-file2-status. - - data division. - file section. - fd indexed-file. - 01 dup-record. - 05 rec-key pic x(5). - 05 rec-value pic x(5). - fd shared-file1. - 01 shared-record1 pic x(10). - fd shared-file2. - 01 shared-record2 pic x(10). - working-storage section. - 01 indexed-file-status pic 99. - 01 shared-file1-status pic 99. - 01 shared-file2-status pic 99. - procedure division. - main-procedure. - - * open the indexed file before the other process does. - open @@open_mode@@ indexed-file. - - * Notify the other process that - * this process opened the indexed file. - open output shared-file1. - close shared-file1. - - * Wait for the other process to finish. - call "C$SLEEP" using 1. - perform forever - open input shared-file2 - if shared-file2-status = 0 - exit perform - end-if - close shared-file2 - call "C$SLEEP" using 1 - end-perform. - close shared-file2. - - * Close the indexed file after the other process has finished. - close indexed-file. -]) - -AT_DATA([prog2.cbl], [ - identification division. - program-id. prog2@@id@@. - - environment division. - input-output section. - - file-control. - select indexed-file - assign to "indexed@@id@@.dat" - organization is indexed - record key is rec-key - file status is indexed-file-status. - - select shared-file1 - assign to "shared1@@id@@.dat" - organization is sequential - file status is shared-file1-status. - - select shared-file2 - assign to "shared2@@id@@.dat" - organization is sequential - file status is shared-file2-status. - - data division. - file section. - fd indexed-file. - 01 dup-record. - 05 rec-key pic x(5). - 05 rec-value pic x(5). - fd shared-file1. - 01 shared-record1 pic x(10). - fd shared-file2. - 01 shared-record2 pic x(10). - working-storage section. - 01 indexed-file-status pic 99. - 01 shared-file1-status pic 99. - 01 shared-file2-status pic 99. - procedure division. - main-procedure. - - * Wait for the other process to open the indexed file. - call "C$SLEEP" using 1. - perform forever - open input shared-file1 - if shared-file1-status = 0 - close shared-file1 - exit perform - end-if - close shared-file1 - call "C$SLEEP" using 1 - end-perform. - - * Open the indexed file that another process has already opened. - open @@open_mode@@ indexed-file. - display indexed-file-status. - close indexed-file. - - * Notify the other process that - * this process finished. - open output shared-file2. - close shared-file2. -]) - -AT_DATA([run.sh], [ -#!/bin/bash - -function run_test() { - SEQ_NUMBER=$1 - OPEN_MODE_1=$2 - OPEN_MODE_2=$3 - EXPECTED_EXIT_CODE=$4 - - rm -f *.dat - - TEST_ID="$(echo "${OPEN_MODE_1}_${OPEN_MODE_2}" | sed 's/-/_/g')" - - PROGRAM_NAME_1="prog1${TEST_ID}" - PROGRAM_NAME_2="prog2${TEST_ID}" - - cat "prog1.cbl" | - sed "s/@@id@@/${TEST_ID}/g" | - sed "s/@@open_mode@@/${OPEN_MODE_1}/g" \ - > ${PROGRAM_NAME_1}.cbl - - cat "prog2.cbl" | - sed "s/@@id@@/${TEST_ID}/g" | - sed "s/@@open_mode@@/${OPEN_MODE_2}/g" \ - > ${PROGRAM_NAME_2}.cbl - - cat "make_indexed_file.cbl" | - sed "s/@@id@@/${TEST_ID}/g" \ - > make_indexed_file${TEST_ID}.cbl - - cobj ${PROGRAM_NAME_1}.cbl ${PROGRAM_NAME_2}.cbl make_indexed_file${TEST_ID}.cbl - - java -Xlog:perf+memops=off make_indexed_file${TEST_ID} - - java -Xlog:perf+memops=off $PROGRAM_NAME_1 & - PID1=$! - - java -Xlog:perf+memops=off $PROGRAM_NAME_2 > ${TEST_ID}.log & - PID2=$! - - wait $PID1 $PID2 - if test "$(cat ${TEST_ID}.log)" != "${EXPECTED_EXIT_CODE}"; then - echo "<${SEQ_NUMBER}> Test ${TEST_ID} failed. Expected exit code: ${EXPECTED_EXIT_CODE}, got: $(cat ${TEST_ID}.log)" \ - exit 1 - fi -} - -################################### - -run_test 00 INPUT INPUT 00 -run_test 01 INPUT OUTPUT 61 -run_test 02 INPUT I-O 00 -run_test 03 INPUT EXTEND 00 -run_test 04 OUTPUT INPUT 61 -run_test 05 OUTPUT OUTPUT 61 -run_test 06 OUTPUT I-O 61 -run_test 07 OUTPUT EXTEND 61 -run_test 08 I-O INPUT 00 -run_test 09 I-O OUTPUT 61 -run_test 10 I-O I-O 00 -run_test 11 I-O EXTEND 00 -run_test 12 EXTEND INPUT 00 -run_test 13 EXTEND OUTPUT 61 -run_test 14 EXTEND I-O 00 -run_test 15 EXTEND EXTEND 00 -]) - -AT_CHECK([bash run.sh]) -AT_CLEANUP