Skip to content

Comments

test codegen for cdcmp#7849

Merged
dlang-bot merged 2 commits intodlang:masterfrom
MartinNowak:cdcmp_test
Feb 9, 2018
Merged

test codegen for cdcmp#7849
dlang-bot merged 2 commits intodlang:masterfrom
MartinNowak:cdcmp_test

Conversation

@MartinNowak
Copy link
Member

@MartinNowak MartinNowak commented Feb 7, 2018

will need a rebase after #7848

@dlang-bot
Copy link
Contributor

dlang-bot commented Feb 7, 2018

Thanks for your pull request, @MartinNowak!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

/* mov rbp,rsp */ 0x48, 0x8b, 0xec,
/* xor eax,eax */ 0x31, 0xc0,
/* pop rbp */ 0x5d,
/* ret */ 0xc3,
Copy link
Member

Choose a reason for hiding this comment

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

These kinds of tests can be extremely tedious to maintain, which is why I abandoned doing them in the past.

They can be much easier if, instead, the object file is run through obj2asm, and the result diffed against a known good file.

Copy link
Contributor

Choose a reason for hiding this comment

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

FYI: the file ships with a generator - it's automatically generate and whenever the codegen changes can be easily, but consciously upgraded.

Copy link
Contributor

@wilzbach wilzbach Feb 9, 2018

Choose a reason for hiding this comment

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

Did you see this comment?

Run env DMD=generated/linux/release/64/dmd rdmd -version=update test/runnable/test_cdcmp.d after codegen changes.

Copy link
Member

Choose a reason for hiding this comment

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

No, I didn't notice it was auto-generated. Thanks for letting me know.

Code!(ubyte, "<", ubyte)([
/* push rbp */ 0x55,
/* mov rbp,rsp */ 0x48, 0x8b, 0xec,
/* sub rsp,0x10 */ 0x48, 0x83, 0xec, 0x10,
Copy link
Member

Choose a reason for hiding this comment

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

All the 0xNN data can get incredibly tedious to create. In the future, use hexStrings -

0x48, 0x83, 0xEC, 0x10,

becomes:

hexString!"48 83 EC 10"

Copy link
Contributor

Choose a reason for hiding this comment

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

This file is auto-generated ;-)

Copy link
Member Author

Choose a reason for hiding this comment

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

HexString relies on phobos, so I avoided that.

import std.regex : ctRegex, matchFirst, replaceFirstInto;
import std.stdio : File, stdout, writeln;
import std.string : strip;
import std.typecons : tuple, EnumMembers;
Copy link
Member

Choose a reason for hiding this comment

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

This means in order for this test file to work, pretty much all of Phobos has to work first. But the dmd tests need to pass before getting Phobos to work, because it is much much easier to debug a code gen problem in test/runnable than it is to try to isolate problems down in Phobos.

Copy link
Member

Choose a reason for hiding this comment

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

A better approach is to do it like test/runnable/iasm.d does, where a pointer to the start of the function is taken and then the generated bytes are compared.

Copy link
Contributor

Choose a reason for hiding this comment

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

No. It's just to automatically update the code blocks. Note version(update) block.
We have a few of these files already in the testsuite ;-)

Copy link
Member

Choose a reason for hiding this comment

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

ok

Copy link
Member Author

Choose a reason for hiding this comment

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

A better approach is to do it like test/runnable/iasm.d does, where a pointer to the start of the function is taken and then the generated bytes are compared.

That's how it's done for the testees, it was just to tedious to update the expectated outcome, so I added an automated update part using objdump. This allows easy diffing and turned out very helpful for the cdvecfill changes where you can see a commit-by-commit diff (https://github.com/dlang/dmd/pull/7003/commits).

Copy link
Contributor

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

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

Ready whenever you are.

@MartinNowak
Copy link
Member Author

MartinNowak commented Feb 9, 2018

We should look to create some small tools/scripts to reduce update boilerplate for those tests, maybe incorporating it into d_do_test or make it a sidekick.
It turns out useful to review codegen changes (as the recent int < 0 one), and improves confidence in doing those changes (here is the diff for the int < 0 fix aab2201).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants