Message ID | pull.776.v4.git.1605647598.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Tue, Nov 17, 2020 at 09:13:14PM +0000, Derrick Stolee via GitGitGadget wrote: > Updates in V4 > ============= > * Eric did an excellent job providing a patch that cleans up several parts > of my series. The most impressive is his mechanism for testing the > platform-specific Git logic in a way that is (mostly) platform-agnostic. > > * Windows doesn't have the 'id' command, so we cannot run the macOS > platform test on Windows. This is easy to resolve. Drop in the following patch and then replace the `$(id -u)` invocation in the test with `$(test-tool getuid)`. This way, the test should work on any platform since both launchctl_get_uid() and `test-tool` will retrieve identical values for UID. --- >8 --- From 84f623bcaec156082c0e7151f40aef18575e6f86 Mon Sep 17 00:00:00 2001 From: Eric Sunshine <sunshine@sunshineco.com> Date: Tue, 17 Nov 2020 18:30:10 -0500 Subject: [PATCH] test-helper: add `getuid` subcommand Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> --- Makefile | 1 + t/helper/test-getuid.c | 7 +++++++ t/helper/test-tool.c | 1 + t/helper/test-tool.h | 1 + 4 files changed, 10 insertions(+) create mode 100644 t/helper/test-getuid.c diff --git a/Makefile b/Makefile index 790a883932..230aff5e5c 100644 --- a/Makefile +++ b/Makefile @@ -706,6 +706,7 @@ TEST_BUILTINS_OBJS += test-dump-untracked-cache.o TEST_BUILTINS_OBJS += test-example-decorate.o TEST_BUILTINS_OBJS += test-genrandom.o TEST_BUILTINS_OBJS += test-genzeros.o +TEST_BUILTINS_OBJS += test-getuid.o TEST_BUILTINS_OBJS += test-hash-speed.o TEST_BUILTINS_OBJS += test-hash.o TEST_BUILTINS_OBJS += test-hashmap.o diff --git a/t/helper/test-getuid.c b/t/helper/test-getuid.c new file mode 100644 index 0000000000..d741302461 --- /dev/null +++ b/t/helper/test-getuid.c @@ -0,0 +1,7 @@ +#include "test-tool.h" + +int cmd__getuid(int argc, const char **argv) +{ + printf("%d\n", getuid()); + return 0; +} diff --git a/t/helper/test-tool.c b/t/helper/test-tool.c index a0d3966b29..ab206541df 100644 --- a/t/helper/test-tool.c +++ b/t/helper/test-tool.c @@ -30,6 +30,7 @@ static struct test_cmd cmds[] = { { "example-decorate", cmd__example_decorate }, { "genrandom", cmd__genrandom }, { "genzeros", cmd__genzeros }, + { "getuid", cmd__getuid }, { "hashmap", cmd__hashmap }, { "hash-speed", cmd__hash_speed }, { "index-version", cmd__index_version }, diff --git a/t/helper/test-tool.h b/t/helper/test-tool.h index 07034d3f38..caee0a3667 100644 --- a/t/helper/test-tool.h +++ b/t/helper/test-tool.h @@ -20,6 +20,7 @@ int cmd__dump_untracked_cache(int argc, const char **argv); int cmd__example_decorate(int argc, const char **argv); int cmd__genrandom(int argc, const char **argv); int cmd__genzeros(int argc, const char **argv); +int cmd__getuid(int argc, const char **argv); int cmd__hashmap(int argc, const char **argv); int cmd__hash_speed(int argc, const char **argv); int cmd__index_version(int argc, const char **argv);
On Tue, Nov 17, 2020 at 4:13 PM Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com> wrote: > * I noticed far too late that while my example XML files had been edited > with UTF-8 encoding, Git is actually writing them as US-ASCII. Somehow > xmllint and launchd are not complaining, but schtasks does complain. > Unfortunately, I cannot find a way to catch this problem other than to > install my tip version on all three platforms and go through the entire > git maintenance start process, and double-check that the processes are > running on the hour. I'm having trouble understanding what problem is being described here and whether or not it has been solved by v4. I might guess that you are saying that `schtasks` insists upon seeing a UTF-8 BOM at the start of the XML file since the XML file declares itself as UTF-8, but that Git is (quite naturally) writing out the file without the UTF-8 BOM. > - xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" > + xml = "<?xml version=\"1.0\" encoding=\"US-ASCII\"?>\n" If the above speculation is correct, and if `schtasks` is happy with the plain text file (lacking UTF-8 BOM) declaring itself as US-ASCII, then this seems a reasonable solution. And it's easy to test that this doesn't get broken. After validating the file with `xmllint`, also grep it for US-ASCII, perhaps like this: test_xmllint "schedule-$frequency.xml" && grep "encoding=.US-ASCII." "schedule-$frequency.xml"
On 11/17/2020 6:36 PM, Eric Sunshine wrote: > On Tue, Nov 17, 2020 at 09:13:14PM +0000, Derrick Stolee via GitGitGadget wrote: >> Updates in V4 >> ============= >> * Eric did an excellent job providing a patch that cleans up several parts >> of my series. The most impressive is his mechanism for testing the >> platform-specific Git logic in a way that is (mostly) platform-agnostic. >> >> * Windows doesn't have the 'id' command, so we cannot run the macOS >> platform test on Windows. > > This is easy to resolve. Drop in the following patch and then replace > the `$(id -u)` invocation in the test with `$(test-tool getuid)`. > This way, the test should work on any platform since both > launchctl_get_uid() and `test-tool` will retrieve identical values for > UID. I was giving your 'test-tool getuid' idea a try, and found that _also_ the $HOME environment variable differs from the format we expect in these subcommands: $HOME: C:\... argument in subcommand: /c/... So, there is another reason why these tests don't work on Windows. I'm of the opinion that maybe it's not worth _that_ level of cross-platform testing. Unless I'm missing something simple about a $HOME alternative here, this seems to be more work than the resulting value. Personally, I'm happy with the benefit you've already provided in allowing Linux to test all platforms. Thanks, -Stolee
On Mon, Nov 23, 2020 at 9:20 PM Derrick Stolee <stolee@gmail.com> wrote: > I was giving your 'test-tool getuid' idea a try, and found that _also_ > the $HOME environment variable differs from the format we expect in these > subcommands: > > $HOME: C:\... > argument in subcommand: /c/... Where does this problem crop up exactly? Is the test doing a literal comparison against the value in $HOME? > So, there is another reason why these tests don't work on Windows. I'm > of the opinion that maybe it's not worth _that_ level of cross-platform > testing. > > Unless I'm missing something simple about a $HOME alternative here, this > seems to be more work than the resulting value. Personally, I'm happy > with the benefit you've already provided in allowing Linux to test all > platforms. Indeed, it's not worth investing a lot of additional time into it. And it's certainly not a good reason to hold up the series. Moreover, this is the sort of thing which can be refined/handled later if someone wants to take a shot at it.
diff --git a/builtin/gc.c b/builtin/gc.c index 955d4b3baf..1a3725429c 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -1642,13 +1642,13 @@ static int launchctl_schedule_plist(const char *exec_path, enum schedule_priorit break; } fprintf(plist, "</array>\n</dict>\n</plist>\n"); + fclose(plist); /* bootout might fail if not already running, so ignore */ launchctl_boot_plist(0, filename, cmd); if (launchctl_boot_plist(1, filename, cmd)) die(_("failed to bootstrap service %s"), filename); - fclose(plist); free(filename); free(name); return 0; @@ -1707,25 +1707,27 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority int result; struct child_process child = CHILD_PROCESS_INIT; const char *xml; - char *xmlpath, *tempDir; - FILE *xmlfp; + char *xmlpath; + struct tempfile *tfile; const char *frequency = get_frequency(schedule); char *name = schtasks_task_name(frequency); - tempDir = xstrfmt("%s/temp", the_repository->objects->odb->path); - xmlpath = xstrfmt("%s/schedule-%s.xml", tempDir, frequency); - safe_create_leading_directories(xmlpath); - xmlfp = xfopen(xmlpath, "w"); + xmlpath = xstrfmt("%s/schedule-%s.xml", + the_repository->objects->odb->path, + frequency); + tfile = create_tempfile(xmlpath); + if (!tfile || !fdopen_tempfile(tfile, "w")) + die(_("failed to create '%s'"), xmlpath); - xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + xml = "<?xml version=\"1.0\" encoding=\"US-ASCII\"?>\n" "<Task version=\"1.4\" xmlns=\"http://schemas.microsoft.com/windows/2004/02/mit/task\">\n" "<Triggers>\n" "<CalendarTrigger>\n"; - fputs(xml, xmlfp); + fputs(xml, tfile->fp); switch (schedule) { case SCHEDULE_HOURLY: - fprintf(xmlfp, + fprintf(tfile->fp, "<StartBoundary>2020-01-01T01:00:00</StartBoundary>\n" "<Enabled>true</Enabled>\n" "<ScheduleByDay>\n" @@ -1739,7 +1741,7 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority break; case SCHEDULE_DAILY: - fprintf(xmlfp, + fprintf(tfile->fp, "<StartBoundary>2020-01-01T00:00:00</StartBoundary>\n" "<Enabled>true</Enabled>\n" "<ScheduleByWeek>\n" @@ -1756,7 +1758,7 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority break; case SCHEDULE_WEEKLY: - fprintf(xmlfp, + fprintf(tfile->fp, "<StartBoundary>2020-01-01T00:00:00</StartBoundary>\n" "<Enabled>true</Enabled>\n" "<ScheduleByWeek>\n" @@ -1771,7 +1773,7 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority break; } - xml= "</CalendarTrigger>\n" + xml = "</CalendarTrigger>\n" "</Triggers>\n" "<Principals>\n" "<Principal id=\"Author\">\n" @@ -1795,11 +1797,10 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority "</Exec>\n" "</Actions>\n" "</Task>\n"; - fprintf(xmlfp, xml, exec_path, exec_path, frequency); - fclose(xmlfp); - + fprintf(tfile->fp, xml, exec_path, exec_path, frequency); strvec_split(&child.args, cmd); strvec_pushl(&child.args, "/create", "/tn", name, "/f", "/xml", xmlpath, NULL); + close_tempfile_gently(tfile); child.no_stdout = 1; child.no_stderr = 1; @@ -1808,8 +1809,7 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority die(_("failed to start schtasks")); result = finish_command(&child); - unlink(xmlpath); - rmdir(tempDir); + delete_tempfile(&tfile); free(xmlpath); free(name); return result; @@ -1850,9 +1850,8 @@ static int crontab_update_schedule(int run_maintenance, int fd, const char *cmd) crontab_list.out = dup(fd); crontab_list.git_cmd = 0; - if (start_command(&crontab_list)) { + if (start_command(&crontab_list)) return error(_("failed to run 'crontab -l'; your system might not support 'cron'")); - } /* Ignore exit code, as an empty crontab will return error. */ finish_command(&crontab_list); @@ -1868,9 +1867,8 @@ static int crontab_update_schedule(int run_maintenance, int fd, const char *cmd) crontab_edit.in = -1; crontab_edit.git_cmd = 0; - if (start_command(&crontab_edit)) { + if (start_command(&crontab_edit)) return error(_("failed to run 'crontab'; your system might not support 'cron'")); - } cron_in = fdopen(crontab_edit.in, "w"); if (!cron_in) { diff --git a/t/t7900-maintenance.sh b/t/t7900-maintenance.sh index e92946c10a..a26ff22541 100755 --- a/t/t7900-maintenance.sh +++ b/t/t7900-maintenance.sh @@ -408,7 +408,7 @@ test_expect_success 'start preserves existing schedule' ' grep "Important information!" cron.txt ' -test_expect_success 'start and stop macOS maintenance' ' +test_expect_success !MINGW 'start and stop macOS maintenance' ' uid=$(id -u) && write_script print-args <<-\EOF && @@ -421,7 +421,6 @@ test_expect_success 'start and stop macOS maintenance' ' # start registers the repo git config --get --global maintenance.repo "$(pwd)" && - # ~/Library/LaunchAgents ls "$HOME/Library/LaunchAgents" >actual && cat >expect <<-\EOF && org.git-scm.git.daily.plist @@ -468,12 +467,12 @@ test_expect_success 'start and stop Windows maintenance' ' EOF rm -f args && - GIT_TEST_MAINT_SCHEDULER="schtasks:/bin/sh print-args" git maintenance start && + GIT_TEST_MAINT_SCHEDULER="schtasks:./print-args" git maintenance start && # start registers the repo git config --get --global maintenance.repo "$(pwd)" && - printf "/create /tn Git Maintenance (%s) /f /xml .git/objects/temp/schedule-%s.xml\n" \ + printf "/create /tn Git Maintenance (%s) /f /xml .git/objects/schedule-%s.xml\n" \ hourly hourly daily daily weekly weekly >expect && test_cmp expect args && @@ -483,7 +482,7 @@ test_expect_success 'start and stop Windows maintenance' ' done && rm -f args && - GIT_TEST_MAINT_SCHEDULER="schtasks:/bin/sh print-args" git maintenance stop && + GIT_TEST_MAINT_SCHEDULER="schtasks:./print-args" git maintenance stop && # stop does not unregister the repo git config --get --global maintenance.repo "$(pwd)" && diff --git a/t/test-lib.sh b/t/test-lib.sh index 4a60d1ed76..ddbeee1f5e 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -1704,7 +1704,8 @@ test_lazy_prereq REBASE_P ' ' # Ensure that no test accidentally triggers a Git command -# that runs 'crontab', affecting a user's cron schedule. -# Tests that verify the cron integration must set this locally +# that runs the actual maintenance scheduler, affecting a user's +# system permanently. +# Tests that verify the scheduler integration must set this locally # to avoid errors. -GIT_TEST_CRONTAB="exit 1" +GIT_TEST_MAINT_SCHEDULER="none:exit 1"