selftests/resctrl: Fix schemata write error check
authorMaciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
Tue, 10 Oct 2023 07:56:11 +0000 (09:56 +0200)
committerShuah Khan <skhan@linuxfoundation.org>
Fri, 13 Oct 2023 20:59:01 +0000 (14:59 -0600)
commit20d96b25cc4c45823fbec5406ae5ae45da6a892e
tree07cfb24f39dc1b48f889db310db3e4bd409c53b3
parentef43c30858754d99373a63dff33280a9969b49bc
selftests/resctrl: Fix schemata write error check

Writing bitmasks to the schemata can fail when the bitmask doesn't
adhere to constraints defined by what a particular CPU supports.
Some example of constraints are max length or having contiguous bits.
The driver should properly return errors when any rule concerning
bitmask format is broken.

Resctrl FS returns error codes from fprintf() only when fclose() is
called. Current error checking scheme allows invalid bitmasks to be
written into schemata file and the selftest doesn't notice because the
fclose() error code isn't checked.

Substitute fopen(), flose() and fprintf() with open(), close() and
write() to avoid error code buffering between fprintf() and fclose().

Remove newline character from the schema string after writing it to
the schemata file so it prints correctly before function return.

Pass the string generated with strerror() to the "reason" buffer so
the error message is more verbose. Extend "reason" buffer so it can hold
longer messages.

Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
tools/testing/selftests/resctrl/resctrlfs.c