LINT: Add cpplint, clang-format and pre-commit support
Change-Id: I3cbb787ef27d90486b212dfb1a8c77c460acc2ac
Signed-off-by: Galantsev, Dmitrii <dmitrii.galantsev@amd.com>
[ROCm/rdc commit: 434e40305d]
This commit is contained in:
Executable → Regular
+11
-12
@@ -20,16 +20,16 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <sys/capability.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "common/rdc_capabilities.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <sys/capability.h>
|
||||
|
||||
namespace amd {
|
||||
namespace rdc {
|
||||
|
||||
int GetCapability(cap_value_t cap, cap_flag_t cap_type, bool *enabled) {
|
||||
int GetCapability(cap_value_t cap, cap_flag_t cap_type, bool* enabled) {
|
||||
cap_t caps;
|
||||
|
||||
assert(enabled != nullptr);
|
||||
@@ -41,7 +41,7 @@ int GetCapability(cap_value_t cap, cap_flag_t cap_type, bool *enabled) {
|
||||
// Get process's current capabilities
|
||||
caps = cap_get_proc();
|
||||
if (caps == nullptr) {
|
||||
return errno;
|
||||
return errno;
|
||||
}
|
||||
|
||||
cap_flag_value_t val;
|
||||
@@ -52,7 +52,7 @@ int GetCapability(cap_value_t cap, cap_flag_t cap_type, bool *enabled) {
|
||||
}
|
||||
|
||||
if (cap_free(caps) == -1) {
|
||||
return errno;
|
||||
return errno;
|
||||
}
|
||||
|
||||
*enabled = (val == CAP_SET ? true : false);
|
||||
@@ -68,16 +68,15 @@ int ModifyCapability(cap_value_t cap, cap_flag_t cap_type, bool enable) {
|
||||
// Get process's current capabilities
|
||||
caps = cap_get_proc();
|
||||
if (caps == nullptr) {
|
||||
return errno;
|
||||
return errno;
|
||||
}
|
||||
|
||||
// the 1 in the call below is the size of the cap_list array
|
||||
cap_list[0] = cap;
|
||||
if (cap_set_flag(caps, cap_type, 1, cap_list, enable ? CAP_SET : CAP_CLEAR)
|
||||
== -1) {
|
||||
if (cap_set_flag(caps, cap_type, 1, cap_list, enable ? CAP_SET : CAP_CLEAR) == -1) {
|
||||
int ret = errno;
|
||||
cap_free(caps);
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (cap_set_proc(caps) == -1) {
|
||||
@@ -87,7 +86,7 @@ int ModifyCapability(cap_value_t cap, cap_flag_t cap_type, bool enable) {
|
||||
}
|
||||
|
||||
if (cap_free(caps) == -1) {
|
||||
return errno;
|
||||
return errno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Executable → Regular
+12
-17
@@ -28,29 +28,24 @@ THE SOFTWARE.
|
||||
namespace amd {
|
||||
namespace rdc {
|
||||
|
||||
int GetCapability(cap_value_t cap, cap_flag_t cap_type, bool *enabled);
|
||||
int GetCapability(cap_value_t cap, cap_flag_t cap_type, bool* enabled);
|
||||
int ModifyCapability(cap_value_t cap, cap_flag_t cap_type, bool enable);
|
||||
|
||||
struct ScopedCapability {
|
||||
ScopedCapability(cap_value_t cp, cap_flag_t cpt) :
|
||||
cap_(cp), cap_type_(cpt), error_(0) {
|
||||
error_ = ModifyCapability(cap_, cap_type_, true);
|
||||
}
|
||||
~ScopedCapability() {
|
||||
error_ = ModifyCapability(cap_, cap_type_, false);
|
||||
}
|
||||
void Relinquish(void) {
|
||||
error_ = ModifyCapability(cap_, cap_type_, false);
|
||||
}
|
||||
int error(void) {return error_;}
|
||||
private:
|
||||
cap_value_t cap_;
|
||||
cap_flag_t cap_type_;
|
||||
int error_;
|
||||
ScopedCapability(cap_value_t cp, cap_flag_t cpt) : cap_(cp), cap_type_(cpt), error_(0) {
|
||||
error_ = ModifyCapability(cap_, cap_type_, true);
|
||||
}
|
||||
~ScopedCapability() { error_ = ModifyCapability(cap_, cap_type_, false); }
|
||||
void Relinquish(void) { error_ = ModifyCapability(cap_, cap_type_, false); }
|
||||
int error(void) { return error_; }
|
||||
|
||||
private:
|
||||
cap_value_t cap_;
|
||||
cap_flag_t cap_type_;
|
||||
int error_;
|
||||
};
|
||||
|
||||
} // namespace rdc
|
||||
} // namespace amd
|
||||
|
||||
#endif // COMMON_RDC_CAPABILITIES_H_
|
||||
|
||||
|
||||
@@ -19,54 +19,48 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
#include "common/rdc_fields_supported.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "common/rdc_fields_supported.h"
|
||||
#include "rdc/rdc.h"
|
||||
namespace amd {
|
||||
namespace rdc {
|
||||
|
||||
#define FLD_DESC_ENT(ID, DESC, LABEL, DISPLAY) \
|
||||
{static_cast<uint32_t>(ID), {#ID, (DESC), (LABEL), (DISPLAY)}},
|
||||
#define FLD_DESC_ENT(ID, DESC, LABEL, DISPLAY) \
|
||||
{static_cast<uint32_t>(ID), {#ID, (DESC), (LABEL), (DISPLAY)}},
|
||||
static const fld_id2name_map_t field_id_to_descript = {
|
||||
#include "common/rdc_field.data"
|
||||
#include "common/rdc_field.data"
|
||||
};
|
||||
#undef FLD_DESC_ENT
|
||||
|
||||
#define FLD_DESC_ENT(ID, DESC, LABEL, DISPLAY) {#ID, (ID)},
|
||||
static fld_name2id_map_t field_name_to_id = {
|
||||
#include "common/rdc_field.data" // NOLINT
|
||||
#include "common/rdc_field.data" // NOLINT
|
||||
};
|
||||
#undef FLD_DESC_ENT
|
||||
|
||||
amd::rdc::fld_id2name_map_t& get_field_id_description_from_id(void) { return field_id_to_descript; }
|
||||
|
||||
bool get_field_id_from_name(const std::string name, rdc_field_t* value) {
|
||||
assert(value != nullptr);
|
||||
auto id = field_name_to_id.find(name);
|
||||
if (id == field_name_to_id.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
amd::rdc::fld_id2name_map_t &
|
||||
get_field_id_description_from_id(void) {
|
||||
return field_id_to_descript;
|
||||
}
|
||||
|
||||
bool get_field_id_from_name(const std::string name, rdc_field_t *value) {
|
||||
assert(value != nullptr);
|
||||
auto id = field_name_to_id.find(name);
|
||||
if (id == field_name_to_id.end()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*value = static_cast<rdc_field_t>(id->second);
|
||||
return true;
|
||||
*value = static_cast<rdc_field_t>(id->second);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool is_field_valid(rdc_field_t field_id) {
|
||||
if (field_id == RDC_FI_INVALID) {
|
||||
return false;
|
||||
}
|
||||
return field_id_to_descript.find(static_cast<uint32_t>(field_id)) !=
|
||||
field_id_to_descript.end();
|
||||
return field_id_to_descript.find(static_cast<uint32_t>(field_id)) != field_id_to_descript.end();
|
||||
}
|
||||
|
||||
|
||||
} // namespace rdc
|
||||
} // namespace amd
|
||||
|
||||
@@ -22,8 +22,8 @@ THE SOFTWARE.
|
||||
#ifndef COMMON_RDC_FIELDS_SUPPORTED_H_
|
||||
#define COMMON_RDC_FIELDS_SUPPORTED_H_
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "rdc/rdc.h"
|
||||
@@ -32,18 +32,17 @@ namespace amd {
|
||||
namespace rdc {
|
||||
|
||||
typedef struct {
|
||||
std::string enum_name;
|
||||
std::string description;
|
||||
std::string label;
|
||||
bool do_display;
|
||||
std::string enum_name;
|
||||
std::string description;
|
||||
std::string label;
|
||||
bool do_display;
|
||||
} field_id_descript;
|
||||
|
||||
typedef const std::map<uint32_t, const field_id_descript>
|
||||
fld_id2name_map_t;
|
||||
typedef const std::map<uint32_t, const field_id_descript> fld_id2name_map_t;
|
||||
typedef std::unordered_map<std::string, uint32_t> fld_name2id_map_t;
|
||||
|
||||
bool get_field_id_from_name(const std::string name, rdc_field_t *value);
|
||||
fld_id2name_map_t & get_field_id_description_from_id(void); // NOLINT
|
||||
bool get_field_id_from_name(const std::string name, rdc_field_t* value);
|
||||
fld_id2name_map_t& get_field_id_description_from_id(void); // NOLINT
|
||||
bool is_field_valid(rdc_field_t field_id);
|
||||
|
||||
} // namespace rdc
|
||||
|
||||
Executable → Regular
+14
-15
@@ -20,28 +20,28 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
#include "common/rdc_utils.h"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <assert.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/stat.h>
|
||||
#include <assert.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
#include "common/rdc_utils.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
namespace amd {
|
||||
namespace rdc {
|
||||
|
||||
bool FileExists(char const *filename) {
|
||||
bool FileExists(char const* filename) {
|
||||
struct stat buf;
|
||||
return (stat(filename, &buf) == 0);
|
||||
}
|
||||
|
||||
int ReadFile(std::string path, std::string *retStr, bool chop_newline) {
|
||||
int ReadFile(std::string path, std::string* retStr, bool chop_newline) {
|
||||
std::stringstream ss;
|
||||
int ret = 0;
|
||||
|
||||
@@ -61,13 +61,12 @@ int ReadFile(std::string path, std::string *retStr, bool chop_newline) {
|
||||
*retStr = ss.str();
|
||||
|
||||
if (chop_newline) {
|
||||
retStr->erase(std::remove(retStr->begin(), retStr->end(), '\n'),
|
||||
retStr->end());
|
||||
retStr->erase(std::remove(retStr->begin(), retStr->end(), '\n'), retStr->end());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ReadFile(const char *path, std::string *retStr, bool chop_newline) {
|
||||
int ReadFile(const char* path, std::string* retStr, bool chop_newline) {
|
||||
assert(path != nullptr);
|
||||
assert(retStr != nullptr);
|
||||
|
||||
@@ -76,11 +75,11 @@ int ReadFile(const char *path, std::string *retStr, bool chop_newline) {
|
||||
return amd::rdc::ReadFile(file_path, retStr, chop_newline);
|
||||
}
|
||||
|
||||
bool IsNumber(const std::string &s) {
|
||||
bool IsNumber(const std::string& s) {
|
||||
return !s.empty() && std::all_of(s.begin(), s.end(), ::isdigit);
|
||||
}
|
||||
|
||||
bool IsIP(const std::string &s) {
|
||||
bool IsIP(const std::string& s) {
|
||||
struct sockaddr_in sa;
|
||||
int result = inet_pton(AF_INET, s.c_str(), &sa);
|
||||
// inet_pton returns 1 on success
|
||||
|
||||
Executable → Regular
+10
-14
@@ -30,29 +30,25 @@ namespace amd {
|
||||
namespace rdc {
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define debug_print(fmt, ...) \
|
||||
do { \
|
||||
#define debug_print(fmt, ...) \
|
||||
do { \
|
||||
} while (false)
|
||||
#else
|
||||
#define debug_print(fmt, ...) \
|
||||
do { \
|
||||
fprintf(stderr, fmt, ##__VA_ARGS__); \
|
||||
#define debug_print(fmt, ...) \
|
||||
do { \
|
||||
fprintf(stderr, fmt, ##__VA_ARGS__); \
|
||||
} while (false)
|
||||
#endif
|
||||
|
||||
bool
|
||||
FileExists(char const *filename);
|
||||
bool FileExists(char const* filename);
|
||||
|
||||
int
|
||||
ReadFile(std::string path, std::string *retStr, bool chop_newline = false);
|
||||
int
|
||||
ReadFile(const char *path, std::string *retStr, bool chop_newline = false);
|
||||
int ReadFile(std::string path, std::string* retStr, bool chop_newline = false);
|
||||
int ReadFile(const char* path, std::string* retStr, bool chop_newline = false);
|
||||
|
||||
bool IsNumber(const std::string &s);
|
||||
bool IsIP(const std::string &s);
|
||||
bool IsNumber(const std::string& s);
|
||||
bool IsIP(const std::string& s);
|
||||
|
||||
} // namespace rdc
|
||||
} // namespace amd
|
||||
|
||||
#endif // COMMON_RDC_UTILS_H_
|
||||
|
||||
|
||||
Reference in New Issue
Block a user