Skip to content

Replace macros in MbedTester to avoid conflicts #14076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 19, 2021

Conversation

gpsimenos
Copy link
Contributor

@gpsimenos gpsimenos commented Dec 21, 2020

Summary of changes

This PR replaces macros in MbedTester with regular constant variables in an unnamed namespace, to avoid conflicts with macros defined elsewhere (e.g. in targets).

Impact of changes

Migration actions required

Documentation


Pull request type

[X] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[X] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers


@ciarmcom ciarmcom added the release-type: patch Indentifies a PR as containing just a patch label Dec 21, 2020
@ciarmcom ciarmcom requested review from a team December 21, 2020 10:00
@ciarmcom
Copy link
Member

@gpsimenos, thank you for your changes.
@ARMmbed/mbed-os-test @ARMmbed/mbed-os-hal @ARMmbed/mbed-os-maintainers please review.

Copy link
Contributor

@0xc0170 0xc0170 left a comment

Choose a reason for hiding this comment

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

This fixes the problem but the other can come in. Shall we fix all these defines that are anyway local?

Let's use unnamed namespace and change to lowercase.

namespace {
    const auto local_variable = 0x1;
}

0xc0170
0xc0170 previously requested changes Jan 5, 2021
Copy link
Contributor

@0xc0170 0xc0170 left a comment

Choose a reason for hiding this comment

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

I should have requested changes rather than comment. Please review and lets fix all of these local variables, not just one.

@adbridge
Copy link
Contributor

adbridge commented Jan 7, 2021

@gpsimenos please add a proper description to the header 'This fixes issue #12675.' is insufficient. Description should contain a summary of the problem and how it has been fixed.

@mergify mergify bot dismissed 0xc0170’s stale review January 8, 2021 12:46

Pull request has been modified.

@gpsimenos gpsimenos changed the title Rename FLASH_SECTOR_SIZE macro to avoid conflicts Replace macros in MbedTester to avoid conflicts Jan 8, 2021
@gpsimenos
Copy link
Contributor Author

Changes pushed and description/title updated.

@gpsimenos gpsimenos requested a review from 0xc0170 January 11, 2021 11:20
@gpsimenos
Copy link
Contributor Author

Ping @0xc0170

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 12, 2021

CI started

@mergify mergify bot added needs: CI and removed needs: work labels Jan 12, 2021
@ladislas
Copy link
Contributor

ladislas commented Jan 12, 2021

Let's use unnamed namespace and change to lowercase.

@0xc0170 IMHO the UPPERCASE makes it more obvious that those are constants defined somewhere.

When you read code like that you won't spot them:

MbedTester::MbedTester(const PinList *form_factor, const PinList *exclude_pins)
    : _form_factor(form_factor), _exclude_pins(exclude_pins), _control_auto(true), _control_valid(false),
      _clk_index(physical_nc), _mosi_index(physical_nc), _miso_index(physical_nc), _aux_index(physical_nc),
      _clk(NULL), _mosi(NULL), _miso(NULL), _aux(NULL)
{

// or 

if (flash.read(buf, start + offset, length_size) != BD_ERROR_OK) {
    sys_pin_mode_disabled();
    return false;
}
if (dest->write(buf, length_size) != length_size) {
    sys_pin_mode_disabled();
    return false;
}
offset += length_size;
uint32_t data_size = (buf[0] << (0 * 8)) |
                     (buf[1] << (1 * 8)) |
                     (buf[2] << (2 * 8)) |
                     (buf[3] << (3 * 8));
if (data_size > firmware_region_size - length_size - crc_size_const) {
    data_size = firmware_region_size - length_size - crc_size_const;
}
const uint32_t firmware_size = data_size + length_size + crc_size_const;

Comment on lines 32 to 38
const auto firmware_size_const = 2192012;
const auto firmware_region_size = 0x220000;
const auto firmware_header_size = 0x10000;
const auto flash_sector_size = 0x1000;
const auto length_size = 0x4;
const auto crc_size_const = 0x4;
const auto flash_spi_freq_hz = 2000000;
const auto analog_count = 4;
Copy link
Contributor

Choose a reason for hiding this comment

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

some variables end with _const some others don't.

I think UPPERCASE makes it more obvious that those are constants.

Suggested change
const auto firmware_size_const = 2192012;
const auto firmware_region_size = 0x220000;
const auto firmware_header_size = 0x10000;
const auto flash_sector_size = 0x1000;
const auto length_size = 0x4;
const auto crc_size_const = 0x4;
const auto flash_spi_freq_hz = 2000000;
const auto analog_count = 4;
const auto FIRMWARE_SIZE = 2192012;
const auto FIRMWARE_REGION_SIZE = 0x220000;
const auto FIRMWARE_HEADER_SIZE = 0x10000;
const auto FLASH_SECTOR_SIZE = 0x1000;
const auto LENGTH_SIZE = 0x4;
const auto CRC_SIZE = 0x4;
const auto FLASH_SPI_FREQ_HZ = 2000000;
const auto ANALOG_COUNT = 4;

Copy link
Contributor

@0xc0170 0xc0170 Jan 12, 2021

Choose a reason for hiding this comment

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

There are variables with internal linkage, uppercase would allow them to clash with the preprocessor and would rather indicate they are macros with external linkage - a reason this PR was proposed is to avoid this.

_const shoud be removed, I'll mark that in the review request.

Copy link
Contributor

Choose a reason for hiding this comment

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

what about the k prefix? or use a named namespace namespace MbedTesterConst {

Copy link
Member

Choose a reason for hiding this comment

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

This file has other sort of inconsistencies. Around line 460 lies global static const arrays in full CAPS.

Moving them all to an MbedTesterConst namespace seems sensible to me.
Lowercase name to avoid clash with preprocessor in a namespace explicit about what those values are is IMHO a good compromise.

I would also recommend to move the magic value for PhysicalIndex to the header file as this is where the type is publicly visible.

@mbed-ci
Copy link

mbed-ci commented Jan 12, 2021

Jenkins CI Test : ✔️ SUCCESS

Build Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️
jenkins-ci/mbed-os-ci_cmake-example-test ✔️

namespace {
const auto physical_pins = 128;
const auto logical_pins = 8;
const auto firmware_size_const = 2192012;
Copy link
Contributor

Choose a reason for hiding this comment

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

lets remove _const suffix from variables here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

@ithinuel ithinuel left a comment

Choose a reason for hiding this comment

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

LGTM

@gpsimenos gpsimenos requested a review from ithinuel January 14, 2021 15:30
@gpsimenos
Copy link
Contributor Author

@0xc0170 Let's CI 😃

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 15, 2021

C istarted

@mergify mergify bot added needs: CI and removed needs: work labels Jan 15, 2021
@mbed-ci
Copy link

mbed-ci commented Jan 15, 2021

Jenkins CI Test : ❌ FAILED

Build Number: 2 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM
jenkins-ci/mbed-os-ci_build-greentea-ARM
jenkins-ci/mbed-os-ci_build-cloud-example-ARM
jenkins-ci/mbed-os-ci_build-example-GCC_ARM
jenkins-ci/mbed-os-ci_build-example-ARM

@gpsimenos
Copy link
Contributor Author

Looks like there's currently some CI instability?

The below errors appear in multiple builds:

ERROR: Unable to clone repository
Cannot contact EC2 (ec2-eu-west-1) - ec2-linux-allinone-builds (i-0014a7eb6c1e4ec0e): hudson.remoting.ChannelClosedException: Channel "unknown": Remote call on EC2 (ec2-eu-west-1) - ec2-linux-allinone-builds (i-0014a7eb6c1e4ec0e) failed. The channel is closing down or has closed down
Could not connect to EC2 (ec2-eu-west-1) - ec2-linux-allinone-builds (i-0014a7eb6c1e4ec0e) to send interrupt signal to process

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 15, 2021

CI restarted

@mbed-ci
Copy link

mbed-ci commented Jan 15, 2021

Jenkins CI Test : ❌ FAILED

Build Number: 3 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-test ✔️
jenkins-ci/mbed-os-ci_greentea-test

@mergify mergify bot added needs: work and removed needs: CI labels Jan 15, 2021
@gpsimenos
Copy link
Contributor Author

@0xc0170 unstable network?

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 18, 2021

Yes, at least 2-3 jobs I found today failed the same way, restarting now

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 18, 2021

CI restarted

@mbed-ci
Copy link

mbed-ci commented Jan 18, 2021

Jenkins CI Test : ✔️ SUCCESS

Build Number: 5 | 🔒 Jenkins CI Job | 🌐 Logs & Artifacts

CLICK for Detailed Summary

jobs Status
jenkins-ci/mbed-os-ci_unittests ✔️
jenkins-ci/mbed-os-ci_build-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_cmake-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-greentea-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-ARM ✔️
jenkins-ci/mbed-os-ci_build-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_build-cloud-example-GCC_ARM ✔️
jenkins-ci/mbed-os-ci_greentea-test ✔️
jenkins-ci/mbed-os-ci_cmake-example-test ✔️

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.

8 participants