Skip to content

Fix ocamltest / Windows / Unicode issues#1357

Merged
gasche merged 5 commits intoocaml:trunkfrom
nojb:make_ocamltest_unicode_aware
Sep 26, 2017
Merged

Fix ocamltest / Windows / Unicode issues#1357
gasche merged 5 commits intoocaml:trunkfrom
nojb:make_ocamltest_unicode_aware

Conversation

@nojb
Copy link
Copy Markdown
Contributor

@nojb nojb commented Sep 19, 2017

This is a first PR to fix some of the CI errors under Windows following the merge of #1200 and #681. It is not yet ready for merging.

Also, some "new" tests are still failing in the compare-native-programs step. I am investigating.

/cc @shindere @dra27

@nojb
Copy link
Copy Markdown
Contributor Author

nojb commented Sep 19, 2017

This PR seems to fix all tests under Windows, except for the compare-native-programs tests of ocamltest. After some detective work with the help of @alainfrisch it seems that the reason is that the PE/COFF executables embed timestamps (in seconds). This makes the test fail sometimes.

One possibility would be to try to skip the portion of the file that contains the timestamp when comparing them, but it may not be so easy because the timestamp appears in more than one place in the executables.

@gasche
Copy link
Copy Markdown
Member

gasche commented Sep 19, 2017

ocamltest already hardcodes the fact that the 512 first bytes of the native programs are ignored under windows: https://github.com/ocaml/ocaml/blob/635b5ed/ocamltest/builtin_actions.ml#L707-L710 . A very conservative approach would be to simply disable this test/action under the same OS conditions.

@nojb
Copy link
Copy Markdown
Contributor Author

nojb commented Sep 20, 2017

Another possibility is to count the number of different bytes (for example, with cmp -l FILE1 FILE2 | wc -l) and succeed as long as this number is not too large.

@gasche
Copy link
Copy Markdown
Member

gasche commented Sep 20, 2017

(Apparently there exists a reasonably portable tool, Ducible, that knows how to strip non-reproducible information from PE executables. I'm pointing it out, but not suggesting to use it from ocamltest, because it adds a lot to the dependency chain (it's 10K lines of C++, and depends on Python 3 for configuration/building).

@nojb
Copy link
Copy Markdown
Contributor Author

nojb commented Sep 21, 2017

Is there a way to trigger AppVeyor on this pull request ?

@gasche
Copy link
Copy Markdown
Member

gasche commented Sep 21, 2017

I will try to close and reopen.

A few remarks by having just a very quick look at the patch:

  • some changes are not ocamltest-related at all (you say it's a Unicode support for the Windows runtime: Let's do it! #1200 merge issue) and I find it a bit confusing to have both kinds of changes in the same PR. Could you send the non-ocamltest-related changes in a separate PR? (In particular, those should not need Sébastien's attention/review).

  • Apologies for the very naive comment (I know nothing of your Windows-Unicode work), but I find it a bit strange that ocamltest/run_stubs.c needs to be changed to use ..._utf16 function, as I assume that this file (unlike run_win32.c) is not Windows-specific. Does that mean that arbitrary OCaml C code will have to use ..._utf16 functions for portability now? Is there a guide on porting applications somewhere? Or is that ocamltest-specific and why?

  • the implementation of disabling native tests on Windows is morally wrong, as you just overloaded the conditional that shows "tests are skipped under flambda" (so after your patch this line will show under non-flambda Windows builds); you should use a new conditional branch with its own meaningful message.

@gasche gasche closed this Sep 21, 2017
@gasche gasche reopened this Sep 21, 2017
@gasche
Copy link
Copy Markdown
Member

gasche commented Sep 21, 2017

(Apparently close-reopen didn't work, I'm not sure why AppVeyor does not work here. Did we recently break the appveyor metadata files? (But they were last touched by #1200 and AppVeyor kept working after we merged that). Did AppVeyor automatically shut off after too many failed build? cc: @avsm)

@nojb
Copy link
Copy Markdown
Contributor Author

nojb commented Sep 21, 2017

Thanks @gasche for the comments.

  • OK, will open a separate PR for the Unicode support for the Windows runtime: Let's do it! #1200 fix.

  • Indeed, C code that is shared between Unix and Windows needs to use the _utf16 functions. In the Unix case these are just defined to be the usual functions, see here. Do you think it is worth introducing a new name for this three functions to be used in C code shared between Unix and Windows ?

  • Indeed, I forgot to fix the message.

@gasche
Copy link
Copy Markdown
Member

gasche commented Sep 21, 2017

Personally I find it fairly confusing to have to use _utf16 functions when my own system doesn't use utf16 anywhere. I would rather expect caml_stat_strdup to do the right thing on systems I don't know about, rather than me learning about the function names they need. But maybe that is too naive and cannot work. Has this been discussed before? Otherwise I would recommend starting a discussion with the development team on an appropriate place -- maybe in the comments for #1200? Or in a Discourse thread?

@gasche
Copy link
Copy Markdown
Member

gasche commented Sep 21, 2017

(I think it's better to have two separate tests with two precise error messages, one for flambda and one for windows, rather than a message that enumerates various possible skipping causes.)

@nojb nojb force-pushed the make_ocamltest_unicode_aware branch from 01c6956 to 56231aa Compare September 21, 2017 07:45
@nojb
Copy link
Copy Markdown
Contributor Author

nojb commented Sep 21, 2017

OK, amended the ocamltest message as suggested and removed unrelated commits, except for one tiny fix to tests/letrec test to avoid a warning when running the testsuite (let me know if I should remove that one as well).

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Sep 21, 2017 via email

@alainfrisch
Copy link
Copy Markdown
Contributor

alainfrisch commented Sep 21, 2017

Personally I find it fairly confusing to have to use _utf16 functions when my own system doesn't use _utf16 anywhere.

I tend to agree. Perhaps just changing the suffix from _utf16 to _sys (or something else) would make it clearer that this is about converting between OCaml strings and the ones expected/returned by the OS (the identity and same types on both sides under *nix, the proper conversion and char* vs wchar* under Windows).

@nojb
Copy link
Copy Markdown
Contributor Author

nojb commented Sep 21, 2017

OK, I will open a new PR with this change and we can continue the discussion there.

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Sep 21, 2017 via email

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Sep 21, 2017 via email

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Sep 21, 2017 via email

@nojb
Copy link
Copy Markdown
Contributor Author

nojb commented Sep 21, 2017

Hi Sébastien,

Either way is fine for me. I can easily rebase the PRs if needed. I propose thus

  1. you make a PR with your two little fixes
  2. I rebase this PR on that
  3. we try to merge this PR without waiting for Fix naming of shared Unicode stubs #1363, since this PR is necessary to fix the Windows tests and Fix naming of shared Unicode stubs #1363 is "cosmetic".

@nojb
Copy link
Copy Markdown
Contributor Author

nojb commented Sep 21, 2017

@shindere Out of curiosity did you try investigating the binary diff of morematch under both compilers ?

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Sep 21, 2017 via email

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Sep 21, 2017 via email

@nojb
Copy link
Copy Markdown
Contributor Author

nojb commented Sep 21, 2017

Well, another possibility is to teach ocamltest a teeny bit of COFF so that it can step over the timestamps. It sounds like a fun exercise.

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Sep 21, 2017 via email

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Sep 21, 2017 via email

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Sep 21, 2017 via email

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Sep 25, 2017 via email

@nojb
Copy link
Copy Markdown
Contributor Author

nojb commented Sep 25, 2017

Only one letter being printed - seems like a WCHAR * is being passed to a function expecting a char *. Will look into it.

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Sep 25, 2017 via email

@shindere
Copy link
Copy Markdown
Contributor

shindere commented Sep 25, 2017 via email

@nojb nojb force-pushed the make_ocamltest_unicode_aware branch 2 times, most recently from 7890250 to c66fe99 Compare September 25, 2017 09:10
@nojb
Copy link
Copy Markdown
Contributor Author

nojb commented Sep 25, 2017

I cannot reproduce the native test failures in my machine. In any case, I added a commit that may fix the error message. The bytecode failures should be fixed by #1362.

If someone could post the _ocamltest logs (or, even better, a .zip with the whole directory) produced by doing make new in testsuite/ in Inria's CI that may help debugging.

@nojb
Copy link
Copy Markdown
Contributor Author

nojb commented Sep 25, 2017

One guess about the native failures in Inria CI: an issue with flexdll.

Are you using the binary 0.36 release ? or the bootstrapped version ? I remember running into some issues when I tried to use the bootstrapped version.

@nojb
Copy link
Copy Markdown
Contributor Author

nojb commented Sep 25, 2017

@shindere I think report_error is essentially correct except for the use of %S to print wide strings which is pretty broken on Windows (we are looking into this with @dra27). Instead, in the last commit I explicitly convert the wide string into UTF-8 which should make it work.

Copy link
Copy Markdown
Contributor

@xavierleroy xavierleroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One serious error spotted. The rest looks reasonable to me but could use a second reading.

settings.logger = logToChannel;
settings.loggerData = Channel(Field(caml_settings, 7));
res = run_command(&settings);
caml_stat_free((charnat *)settings.program);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this cast (and several other below) to charnat * ? caml_stat_free takes void * arguments.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is confusing: the right fix is not to define the struct fields (see https://github.com/ocaml/ocaml/blob/trunk/ocamltest/run.h#L32-L34) as being const char * in the original code. Will fix.

error_with_location(file, line,
settings, "%s: %s", message, error_message);
settings, "%s: %s", message, error_message_c);
caml_stat_free(error_message);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AAAARGH! You're freeing the wrong error_message!!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, how embarrassing! (there should be a warning somewhere about writing C with less than 5 hours of sleep...)

@xavierleroy
Copy link
Copy Markdown
Contributor

xavierleroy commented Sep 25, 2017

One guess about the native failures in Inria CI: an issue with flexdll.

That was the case until recently, but now the whole system builds and runs the test suite, it's just the ocamltest-administered tests that report errors.

I'm confident that the changes from the present PR will address this issue;. Let's just have them reviewed and finished as quickly as possible so that we can merge and try again.

@nojb nojb force-pushed the make_ocamltest_unicode_aware branch from b6dd129 to a750eb4 Compare September 25, 2017 11:54
@nojb
Copy link
Copy Markdown
Contributor Author

nojb commented Sep 25, 2017

Fixed and rebased.

Copy link
Copy Markdown
Member

@damiendoligez damiendoligez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reviewed the diff and I think it's good.
@xavierleroy you'll need to change your review status...

@damiendoligez damiendoligez added this to the 4.06.0 milestone Sep 25, 2017
@shindere
Copy link
Copy Markdown
Contributor

Could not go very far with the tests but I think it would be great to
have this PR merged and perhaps also #1363. Indeed, the interaction between
ocamltest (#681) and Unicode support for Windows (#1200) could not be tested
very well and I think several of the failures that are actually encountered
on Inria's CI come from that. For instance, even the names of the files that
are created to store compiler outputs look weird.

So, my suggestion would be to merge these PRs if they are okay and I expect
the number of failures on Inria's CI to decrease. Then we can see what
errors are left and not due to this interaction.

@gasche gasche merged commit 7cc4e6d into ocaml:trunk Sep 26, 2017
@gasche
Copy link
Copy Markdown
Member

gasche commented Sep 26, 2017

Merged.

@gasche
Copy link
Copy Markdown
Member

gasche commented Sep 26, 2017

Note that #1363 conflicts with the present PR, if I understand correctly (the present one uses the pre-1363 names). I'll ask @nojb to rebase taking this code into account.

@nojb
Copy link
Copy Markdown
Contributor Author

nojb commented Sep 26, 2017

Thanks! Will rebase right away!

gasche added a commit that referenced this pull request Sep 26, 2017
Fix ocamltest / Windows / Unicode issues
@gasche
Copy link
Copy Markdown
Member

gasche commented Sep 26, 2017

Cherry-picked in 4.06 [ 9aebb96 ]. (Cherry-pick squashed so history is lost, but (1) it was not that clean anyway and (2) this is just in the release branch, trunk has full history.)

@gasche gasche mentioned this pull request Sep 29, 2017
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
* Add changelog for dune 3.9.0

* Minor improvements

* Update data/changelog/dune/2023-06-30-dune-3.9.0.md

Co-authored-by: Christine Rose <christinerose@users.noreply.github.com>

---------

Co-authored-by: Thibaut Mattio <thibaut.mattio@gmail.com>
Co-authored-by: Christine Rose <christinerose@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants