<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:DengXian;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@DengXian";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="blue" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">I can test it again, but I hit a compiler complaint around the STATIC CONST solution.</p>
<p class="MsoNormal">Also, it doesn’t apply in all cases because I have at lease half a dozen cases that say “test X, prove negative, twiddle value, test Y, prove positive”.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I’ll try a few more things, but I may reissue the patch series and withhold the tests until they can be rewritten to match. I don’t want them to hold up VarPol any longer.</p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">- Bret <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="mso-element:para-border-div;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="border:none;padding:0in"><b>From: </b><a href="mailto:lersek@redhat.com">Laszlo Ersek</a><br>
<b>Sent: </b>Wednesday, October 7, 2020 8:51 AM<br>
<b>To: </b><a href="mailto:afish@apple.com">Andrew Fish</a>; <a href="mailto:devel@edk2.groups.io">
devel@edk2.groups.io</a><br>
<b>Cc: </b><a href="mailto:michael.d.kinney@intel.com">Kinney, Michael D</a>; <a href="mailto:Bret.Barkelew@microsoft.com">
Bret Barkelew</a><br>
<b>Subject: </b>[EXTERNAL] Re: [edk2-devel] VariablePolicy: Final Changes Thread 2 - ECC & UnitTest</p>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt">On 10/07/20 16:27, Andrew Fish wrote:<br>
> For case 1 I thought the size had to be > 8 bytes, not just a struct? Maybe that is compiler specific?<br>
<br>
Honestly, I've got no clue. I just remember we must avoid initializers<br>
for objects that do not have static storage duration.<br>
<br>
Laszlo<br>
<br>
> <br>
> Sent from my iPhone<br>
> <br>
>> On Oct 7, 2020, at 6:43 AM, Laszlo Ersek <lersek@redhat.com> wrote:<br>
>><br>
>> On 10/07/20 03:46, Michael D Kinney wrote:<br>
>>><br>
>>> Bret,<br>
>>><br>
>>> Initializing variable in declaration for structures and arrays<br>
>>> introduces use of intrinsics.  Since it is possible for unit test<br>
>>> sources to be used for both host and target tests, I recommend we<br>
>>> continue to follow the EDK II coding style for unit tests to support<br>
>>> maximum compatibility and code reuse.<br>
>>><br>
>>> Using a module global variable with initializers instead of<br>
>>> initializing a local declaration is the same amount of work, so I do<br>
>>> not believe that will result in fewer tests.<br>
>>><br>
>>> I agree it is useful to have the test data next to the test code. This<br>
>>> can be accomplished by breaking up into more files so the test data is<br>
>>> immediately above the test function the test data is used.  Does ECC<br>
>>> raise an error if a module global is placed between 2 functions?  A<br>
>>> 2nd approach to put the module global immediately above the test<br>
>>> function the test data is used.<br>
>><br>
>> Consider the following example structure type, for the sake of<br>
>> discussion:<br>
>><br>
>>  typedef struct {<br>
>>    UINT32 Value;<br>
>>  } TEST_DATA;<br>
>><br>
>><br>
>> * Case#1: block scope, automatic storage duration<br>
>><br>
>>  EFI_STATUS<br>
>>  FoobarTest (<br>
>>    VOID<br>
>>    )<br>
>>  {<br>
>>    TEST_DATA TestData = { 42 };<br>
>>    // ...<br>
>>  }<br>
>><br>
>> Problem: uses intrinsics.<br>
>><br>
>><br>
>> * Case#2: file scope, static storage duration.<br>
>><br>
>>  STATIC CONST TEST_DATA mTestData = { 42 };<br>
>><br>
>>  EFI_STATUS<br>
>>  FoobarTest (<br>
>>    VOID<br>
>>    )<br>
>>  {<br>
>>    // ...<br>
>>  }<br>
>><br>
>> Problem: either "mTestData" is textually far from FoobarTest(), or -- if<br>
>> we keep them close to each other -- we mix variable definitions with<br>
>> function definitions, at file scope.<br>
>><br>
>><br>
>> * Case #3: block scope, static storage duration.<br>
>><br>
>>  EFI_STATUS<br>
>>  FoobarTest (<br>
>>    VOID<br>
>>    )<br>
>>  {<br>
>>    STATIC CONST TEST_DATA TestData = { 42 };<br>
>>    // ...<br>
>>  }<br>
>><br>
>> Problem: there should be none. Does not involve intrinsics, and the<br>
>> object definition is part of the function's scope.<br>
>><br>
>><br>
>> If ECC does not recognize case#3 as valid, then that is an *ECC bug*.<br>
>><br>
>> ECC has no reason to prevent case#3, as case#3 does not involve<br>
>> intrinsics, and is a generally valid and useful C language construct (it<br>
>> combines the life cycle of case#2 with the visibility of case#1).<br>
>><br>
>> Again, if ECC rejects case#3, that's *definitely* a bug in ECC, and we<br>
>> should fix it first. Given that ECC includes a full-blown C language<br>
>> parser, the fix should not be too difficult -- check if the declaration<br>
>> has the "static" storage-class specifier.<br>
>><br>
>> ... In fact, I think that purely CONST-qualifying TestData might suffice<br>
>> for shutting up ECC. See the following in<br>
>> "BaseTools/Source/Python/Ecc/c.py", method<br>
>> "CheckFuncLayoutLocalVariable":<br>
>><br>
>>>        for Result in ResultSet:<br>
>>>            if len(Result[1]) > 0 and 'CONST' not in Result[3]:<br>
>>>                PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_NO_INIT_OF_VARIABLE, 'Variable Name: %s' % Result[0], FileTable, Result[2])<br>
>><br>
>> So case#3 should work through that avenue already, because case#3 has<br>
>> CONST *too*.<br>
>><br>
>> Now, in case#3, if "TestData" needs to undergo modifications, and so<br>
>> CONST is not immediately desirable, that's solvable:<br>
>><br>
>>  EFI_STATUS<br>
>>  FoobarTest (<br>
>>    VOID<br>
>>    )<br>
>>  {<br>
>>    STATIC CONST TEST_DATA TestDataTemplate = { 42 };<br>
>>    TEST_DATA TestData;<br>
>><br>
>>    CopyMem (&TestData, TestDataTemplate, sizeof (TEST_DATA));<br>
>>    // ...<br>
>>  }<br>
>><br>
>> Thanks<br>
>> Laszlo<br>
>><br>
>>><br>
>>> Best regards,<br>
>>><br>
>>> Mike<br>
>>><br>
>>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Bret Barkelew via groups.io<br>
>>> Sent: Tuesday, October 6, 2020 5:28 PM<br>
>>> To: devel@edk2.groups.io<br>
>>> Subject: [edk2-devel] VariablePolicy: Final Changes Thread 2 - ECC & UnitTest<br>
>>><br>
>>> Ive worked through all the ECC issues with Variable Policy (AND the UnitTests) on this branch:<br>
>>> Commits · corthon/edk2 (github.com)<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcorthon%2Fedk2%2Fcommits%2Fvar_policy_dev_submission_v8&amp;data=04%7C01%7Cbret.barkelew%40microsoft.com%7C8286accbe81740bde8cc08d86ad8c8ae%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637376826604910138%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=XSNAxTGdbKGlrPLV%2BqWVNEAQjyyeSoKQ8zcfG1%2B4W1s%3D&amp;reserved=0><br>
>>><br>
>>> I even wrote the Main() entry point lib that Laszlo suggested (it works rather nicely):<br>
>>> TEMP: Staging for HostTest entry point · corthon/edk2@4ce5210 (github.com)<https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcorthon%2Fedk2%2Fcommit%2F4ce52108b3e1bcb2ba78995be94c3949fe647eda&amp;data=04%7C01%7Cbret.barkelew%40microsoft.com%7C8286accbe81740bde8cc08d86ad8c8ae%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637376826604910138%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=46MZeja1WTnq44vSZOwJQ%2BAs61TbdFQtFfyj7wgm5mY%3D&amp;reserved=0><br>
>>><br>
>>> However, theres one that I just cant get past and I would like to take it up with the community. I dont think that UnitTests should have to deal with the cant initialize variables in declaration check. Almost none of the solutions that I tested worked,
 and the ones that did were too cumbersome. They failed on two key points that are important for test writing:<br>
>>><br>
>>>  *   They were annoying to write ===> fewer tests.<br>
>>>  *   They moved even more of the test case data away from the test ===> harder to read tests.<br>
>>><br>
>>> I would like to move for an exception for unit tests (or at least host-based unit tests), but I dont know how to accomplish that from a technical standpoint.<br>
>>><br>
>>> Thoughts?<br>
>>><br>
>>> - Bret<br>
>>><br>
>>><br>
>>><br>
>>><br>
>>><br>
>>><br>
>>><br>
>><br>
>><br>
>><br>
>> <br>
>><br>
>><br>
> <o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</body>
</html>


 <div width="1" style="color:white;clear:both">_._,_._,_</div> <hr> Groups.io Links:<p>   You receive all messages sent to this group.    <p> <a target="_blank" href="https://edk2.groups.io/g/devel/message/65994">View/Reply Online (#65994)</a> |    |  <a target="_blank" href="https://groups.io/mt/77366170/1813853">Mute This Topic</a>  | <a href="https://edk2.groups.io/g/devel/post">New Topic</a><br>    <a href="https://edk2.groups.io/g/devel/editsub/1813853">Your Subscription</a> | <a href="mailto:devel+owner@edk2.groups.io">Contact Group Owner</a> |  <a href="https://edk2.groups.io/g/devel/unsub">Unsubscribe</a>  [edk2-devel-archive@redhat.com]<br> <div width="1" style="color:white;clear:both">_._,_._,_</div>