Skip to content

Add rspec test to validate config format #365

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 1 commit into from
May 9, 2024

Conversation

yeetengangIntel
Copy link

@yeetengangIntel yeetengangIntel commented Apr 15, 2024

Fix for issue #241

  • Check config format for need_kconfig part
  • Format requirements:
    1. Config name not start with CONFIG_
    2. Config value only contain n, m, y, i386, x86_64, or empty

@yeetengangIntel yeetengangIntel force-pushed the open-src/need-kconfig-format-spec-2 branch 5 times, most recently from 45f0f9f to a5314bd Compare April 15, 2024 09:23
@yeetengangIntel
Copy link
Author

For now there are 4 files in /include directory that does not met the requirements due to integers or multiple values passed in:

  1. include/ndctl
  2. include/kernel-selftests
  3. include/blktests
  4. include/kernel-selftests-bpf
    @rli9 Based on issue 241 require config value to only contain n, m, y, i386, x86_64, or empty, so would like to check if these 4 files values are expected?
    image

value.all? { |v| v.match(allowed_chars) || v.empty? }
else
value.match(allowed_chars) || value.empty?
end
Copy link

Choose a reason for hiding this comment

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

probably the code can be combined as

Array(value).all? { |v| v.match(allowed_chars) || v.empty? }

But would value.is_a?(Array) become true, since early code has converted the value to String.

def check_config_value(value)
# Check if value format is valid:
# 1. only contain n, m, y or nothing
# 2. only contain i386, x86_64, or nothing
Copy link

Choose a reason for hiding this comment

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

Sorry, I need update the requirement that int is allowed (a valid value). Could you help handle int as well?

def check_config_name(name)
# Check if config name format is valid:
# 1. not start with CONFIG_
!name.to_s.start_with?('CONFIG_')
Copy link

Choose a reason for hiding this comment

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

thanks, prefer the logic to be

expect(name.to_s).to be_start_with('CONFIG_')

So it checks the expected pattern by expect method, and when it fails, the failure output could be more direct to show what the wrong name is.


# If the value is an array, check each element seperately
if value.is_a?(Array)
value.all? { |v| v.match(allowed_chars) || v.empty? }
Copy link

@rli9 rli9 Apr 15, 2024

Choose a reason for hiding this comment

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

similarly, I think here the code could be

value.all? { |v| expect(v).to match(allowed_chars) }

BTW: v.empty? check looks to be not necessary, since the pattern inclues empty string.

files.each do |file|
begin
yaml_data = load_yaml_with_conditionals(file)
next if yaml_data.nil? || !yaml_data.is_a?(Hash)
Copy link

Choose a reason for hiding this comment

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

could be

next unless yaml_data.is_a?(Hash)

@rli9
Copy link

rli9 commented Apr 15, 2024

Based on issue 241 require config value to only contain n, m, y, i386, x86_64, or empty, so would like to check if these 4 files values are expected?

Sorry, the int value is also valid. I didn't mention it in the initial issue.

@rli9
Copy link

rli9 commented May 7, 2024

Thanks, can you help combine all commits into a single one?

@yeetengangIntel yeetengangIntel force-pushed the open-src/need-kconfig-format-spec-2 branch 2 times, most recently from d20b6ec to 08551aa Compare May 9, 2024 02:23
* Check config format for need_kconfig in /include
* Format requirements:
  i. Config name not start with CONFIG_
  ii. Config valu only contain n, m, y, i386, x86_64, integers, hexadecimal, or empty
@rli9 rli9 merged commit 16717da into intel:master May 9, 2024
8 checks passed
@rli9
Copy link

rli9 commented May 9, 2024

thanks for the patch

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.

2 participants