[Toybox] [PATCH] Fix truncate.test for macOS.
Rob Landley
rob at landley.net
Thu Jun 23 23:54:54 PDT 2022
On 6/22/22 20:02, enh wrote:
> On Wed, Jun 22, 2022 at 1:52 PM Rob Landley <rob at landley.net
> <mailto:rob at landley.net>> wrote:
The problem with the mac tar test is even though it's easy enough to find what
/etc/passwd calls UID 0:
ROOT="$(sed -n '/[^:]*:[^:]*:0:/s/:.*//p' /etc/passwd)"
That doesn't change the fact it'll be putting a different string into the
tarball, with different sha1sums. Um. (I was using "root" as the one known
constant account that didn't vary across distros. Possibly I need a way to tell
it to use an alternate /etc/passwd file to lookup usernames. This is why I've
been poking at mkroot, but making that work on a mac is just... ow.)
> On 6/20/22 21:32, enh via Toybox wrote:
> > Specifically we were ending up with 2048 blocks allocated, and that --
> > not the stat(1) behavior -- was the reason why this test was failing
> > on macOS.
>
> Yay, I got thunderbird sending email through gmail again! (The version upgrade
> changed the authentication type in the smtp server settings, but I could still
> set it BACK...)
>
> I wanted a partially sparse file there, which truncate was preserving the
> contents of.
>
> i must be missing something ... why is it _partially_ sparse?
Because truncate should be able to extend an existing file sparsely without
damaging the existing contents, but I see that the existing test wasn't doing
what I thought it was doing...
So hang on, if we made a file completely sparse in 3 segments, how many blocks
does MacOS think it's allocated? Can I dig this out of the macos test log on github?
https://github.com/landley/toybox/runs/7008521598?check_suite_focus=true
scripts/test.sh
scripts/runtest.sh: line 223: syntax error near unexpected token `;'
scripts/runtest.sh: line 223: ` R) LEN=0; B=1; ;&'
It _starts_ with a syntax error, and THEN proceeds to run the tests. I don't
understand what it's doing here?
Scroll, scroll, scroll through the test results. VERBOSE=allnopass is probably
your friend here...
No it does not. And I don't have a mac to try this on. Hmmm...
> There's %b and %B which is block size and size per block, and bash
> can do:
>
> $ x=1+3; echo $((x))
> 4
>
> So what I should probably do is:
>
> X=$(stat -c %B); [ $(($(stat -c %b freep)*X)) -le $((12345+X)) ]]
Except toybox --help stat says "%b Size/512" so the units SHOULD be 512. It's
never NOT 512 in Linux, and I remember a certain amount of digging to confirm
this at the time? Hmmm. (Is the "right fix" to get the macos build to behave
like the linux build?)
> The problem is, you're not using bash or toysh for these tests, you're using a
> shell of unknown capabilities. Can the macos and android shells do that?
>
> macos _is_ bash, it's just 3.2.57 from 2007, for exactly the reason you'd assume.
They swapped to zsh three years ago:
https://www.theverge.com/2019/6/4/18651872/apple-macos-catalina-zsh-bash-shell-replacement-features
That said I THINK all this $((math)) stuff I've been proposing is posix? So it
should work...?
> android is mksh, which is available as a debian package; i often do "android"
> shell testing that way for convenience :-)
>
> if you send me a patch i can test it for you ... but feel free to just commit
> "the right thing" and we can work from there!
I'm no longer convinced I know what the right thing is here. Possibly the
"delete and recreate" workaround is best, but I have no idea WHY it works...
I'm tempted to borrow my wife's mac for a bit, but I have no idea how to set up
a development environment on a mac. The first google hit is
https://sourabhbajaj.com/mac-setup/Xcode/ which looks... more elaborate than I
want to do on a borrowed machine.
Rob
More information about the Toybox
mailing list