Merge branch 'master' into gcc_warns

This commit is contained in:
Jack Marriott
2018-12-04 18:26:05 -08:00
committed by GitHub
13 changed files with 548 additions and 15 deletions

View File

@@ -1,14 +0,0 @@
#!/usr/bin/env python3
from lcov_cobertura import LcovCobertura
LCOV_FILE = 'build/coverage/test-coverage.info'
OUT_FILE = 'build/coverage/test-coverage.xml'
with open(LCOV_FILE) as fr:
data = fr.read()
converter = LcovCobertura(data)
res = converter.convert()
with open(OUT_FILE, 'w') as fw:
fw.write(res)

46
firmware/ec/Jenkinsfile vendored Normal file
View File

@@ -0,0 +1,46 @@
/*
* Copyright (c) 2018-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
node {
currentBuild.result = 'SUCCESS'
withEnv(["UNITY_ROOT=$HOME/Unity", "TOOLCHAIN=$HOME/gcc-arm-none-eabi", "OCWARE_DIR=./"]) {
stage('Checkout') {
step([$class: 'WsCleanup'])
echo 'Checking out SCM'
checkout scm
}
try {
stage('Static Analysis') {
sh 'bash firmware/utilities/jenkins/clang_patch'
}
} catch (err) {
currentBuild.result = 'ERROR'
} finally {
archiveArtifacts '**/clang_format.patch'
}
try {
stage('Build and Unit Test') {
dir ("firmware/ec"){
sh 'make ci'
sh 'python3 ../utilities/jenkins/coverage.py'
}
}
} catch (err) {
currentBuild.result = 'FAILURE'
} finally {
warnings consoleParsers: [[parserName: 'GNU Make + GNU C Compiler (gcc)']]
junit 'firmware/ec/test/build/results/unit-test-results.xml'
step([$class: 'CoberturaPublisher', autoUpdateHealth: false, autoUpdateStability: false,\
coberturaReportFile: '**/test-coverage.xml', failUnhealthy: false, failUnstable: false,\
maxNumberOfBuilds: 0, onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false])
}
}
}

View File

@@ -119,6 +119,7 @@ test:
cd test && $(MAKE) $(TESTFLAGS)
ci: TESTFLAGS = ci
ci: CFLAGS += -Wextra -Wpointer-arith -Wcast-align -Wwrite-strings -Wswitch-default -Wunreachable-code -Winit-self -Wno-missing-field-initializers -Wno-unknown-pragmas -Wstrict-prototypes -Wundef
ci: CFLAGS += -ftest-coverage
ci: all test

View File

@@ -272,6 +272,7 @@ pwr_process_get_status_parameters_data(ePower_StatusParamId paramIndex,
uint8_t *pPowerStatusData)
{
ReturnStatus status = RETURN_OK;
*pPowerStatusData = 0;
switch (paramIndex) {
case PWR_STAT_POE_AVAILABILITY: {
if ((Power_SourceInfo[PWR_SRC_POE].state == PWR_SRC_ACTIVE) ||

View File

@@ -163,6 +163,9 @@ $(PATHB)Test_OcGpio$(TARGET_EXTENSION): $(STD_FILES) $(TEST_OCGPIO_SRC)
TEST_OCMP_LTC4015_SRC=$(OCWARE_ROOT)/src/devices/ocmp_wrappers/ocmp_ltc4015.c $(OCWARE_ROOT)/src/devices/ltc4015.c $(OCWARE_ROOT)/src/drivers/GpioSX1509.c $(OCWARE_ROOT)/src/devices/sx1509.c $(OCWARE_ROOT)/src/helpers/memory.c $(OCWARE_ROOT)/src/devices/i2cbus.c fake/fake_GPIO.c fake/fake_I2C.c fake/fake_ThreadedISR.c stub/stub_GateMutex.c stub/stub_GateMutex.c stub/stub_ltc4015.c $(OCWARE_ROOT)/src/post/post_util.c fake/fake_SX1509_register.c fake/fake_ltc4015_register.c $(OCWARE_ROOT)/platform/oc-sdr/cfg/OC_CONNECT_GBC.c
$(PATHB)Test_ocmp_ltc4015$(TARGET_EXTENSION): $(STD_FILES) $(TEST_OCMP_LTC4015_SRC) $(INC_M)
TEST_OCMP_powerSource_SRC=$(OCWARE_ROOT)/src/devices/ocmp_wrappers/ocmp_powerSource.c $(OCWARE_ROOT)/src/devices/powerSource.c $(OCWARE_ROOT)/src/drivers/GpioSX1509.c $(OCWARE_ROOT)/src/devices/sx1509.c $(OCWARE_ROOT)/src/helpers/memory.c $(OCWARE_ROOT)/src/devices/i2cbus.c fake/fake_GPIO.c fake/fake_I2C.c fake/fake_ThreadedISR.c stub/stub_GateMutex.c stub/stub_GateMutex.c $(OCWARE_ROOT)/src/post/post_util.c fake/fake_SX1509_register.c fake/fake_powerSource.c $(OCWARE_ROOT)/platform/oc-sdr/cfg/OC_CONNECT_GBC.c
$(PATHB)Test_ocmp_powerSource$(TARGET_EXTENSION): $(STD_FILES) $(TEST_OCMP_powerSource_SRC) $(INC_M)
$(PATHB)%$(TARGET_EXTENSION):
$(C_COMPILER) $(CFLAGS) $(INC_DIRS) $(SYMBOLS) $^ -o $@
$(COV_CMDS)

View File

@@ -208,6 +208,8 @@ bool I2C_transfer(I2C_Handle handle, I2C_Transaction *transaction)
* in chunks in the event that we have 16-bit (or larger) registers with
* a different endianness than the host */
if (write_count > 0) {
write_count =
((dev->addr_size) * (transaction->writeCount)) - dev->addr_size;
size_t write_size = MIN(write_count, dev->tbl_size - reg_addr);
for (size_t i = 0; i < write_size / dev->reg_size; i += dev->reg_size) {
endian_conversion(write_buf + i, dev->reg_size, dev->endianness,

View File

@@ -0,0 +1,37 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include "include/test_powerSource.h"
#include <stdint.h>
extern const OcGpio_FnTable GpioSX1509_fnTable;
bool PWR_GpioPins[] = {
[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_ENABLE,
[OC_EC_PWR_PRSNT_POE] = PWR_STATE_ENABLE,
};
uint32_t PWR_GpioConfig[] = {
[OC_EC_PWR_PRSNT_SOLAR_AUX] = OCGPIO_CFG_INPUT,
[OC_EC_PWR_PRSNT_POE] = OCGPIO_CFG_INPUT,
};
/* ============================= Boilerplate ================================ */
OcGpio_Port ec_io = {
.fn_table = &FakeGpio_fnTable,
.object_data = &(FakeGpio_Obj){},
};
OcGpio_Port gbc_io_0 = {
.fn_table = &GpioSX1509_fnTable,
.cfg =
&(SX1509_Cfg){
.i2c_dev = { I2C_BUS, I2C_ADDR },
},
.object_data = &(SX1509_Obj){},
};

View File

@@ -0,0 +1,48 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#ifndef _TEST_POWERSOURCE_H
#define _TEST_POWERSOURCE_H
#include "common/inc/global/Framework.h"
#include "common/inc/ocmp_wrappers/ocmp_powersource.h"
#include "drivers/GpioSX1509.h"
#include "drivers/OcGpio.h"
#include "fake/fake_GPIO.h"
#include "fake/fake_I2C.h"
#include "fake/fake_ThreadedISR.h"
#include "helpers/array.h"
#include "helpers/attribute.h"
#include "helpers/memory.h"
#include "inc/devices/powerSource.h"
#include "include/test_sx1509.h"
#include <string.h>
#include "unity.h"
/* ======================== Constants & variables =========================== */
#define I2C_ADDR 0x71
#define I2C_BUS 5
#define OC_EC_PWR_INVALID_IO 0x82
#define OC_EC_PWR_INVALID_PIN 0x57
#define OC_EC_PWR_PRSNT_POE 0x55
#define OC_EC_PWR_PRSNT_SOLAR_AUX 0x1E
#define PWR_EXT_BAT_ENABLE_FIRST_BYTE 0x08
#define PWR_EXT_BAT_ENABLE_SECOND_BYTE 0x00
#define PWR_INT_BAT_ENABLE_FIRST_BYTE 0x10
#define PWR_INT_BAT_ENABLE_SECOND_BYTE 0x00
#define PWR_INT_EXT_BAT_DISABLE_FIRST_BYTE 0x18
#define PWR_INT_EXT_BAT_DISABLE_SECOND_BYTE 0x00
#define PWR_STATE_DISABLE 0x01
#define PWR_STATE_ENABLE 0x00
#define PWR_STATE_INVALID_PARAM 0x09
typedef enum ePowerSourceStatus {
PWR_SRC_NOT_AVAILABLE = 0,
PWR_SRC_ACTIVE_AVAILABLE,
} ePowerSourceStatus;
#endif

View File

@@ -11,7 +11,7 @@
#include <stdint.h>
/*Enumes are defined as per the SX1509 datasheet*/
/* Enumes are defined as per the SX1509 datasheet */
typedef enum SX1509Regs {
SX1509_REG_INPUT_DISABLE_B = 0x00,
SX1509_REG_INPUT_DISABLE_A,

View File

@@ -0,0 +1,300 @@
/**
* Copyright (c) 2017-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include "include/test_powerSource.h"
extern bool PWR_GpioPins[OC_EC_PWR_PRSNT_POE];
extern const OcGpio_FnTable GpioSX1509_fnTable;
extern OcGpio_Port ec_io;
extern OcGpio_Port gbc_io_0;
extern PWRSRC_Dev gbc_pwr_powerSource;
extern PWRSRC_Dev gbc_pwr_powerSource_invalid;
extern uint32_t PWR_GpioConfig[OC_EC_PWR_PRSNT_POE];
extern uint8_t SX1509_regs[SX1509_REG_TEST_2];
/* ============================= Boilerplate ================================ */
void suite_setUp(void)
{
FakeGpio_registerDevSimple(PWR_GpioPins, PWR_GpioConfig);
fake_I2C_init();
fake_I2C_registerDevSimple(I2C_BUS, I2C_ADDR, SX1509_regs,
sizeof(SX1509_regs), sizeof(SX1509_regs[0]),
sizeof(uint8_t), FAKE_I2C_DEV_LITTLE_ENDIAN);
}
void setUp(void)
{
memset(SX1509_regs, 0, sizeof(SX1509_regs));
OcGpio_init(&gbc_io_0);
}
void tearDown(void)
{
}
void suite_tearDown(void)
{
fake_I2C_deinit();
}
/* ================================ Tests =================================== */
void test_ocmp_powerSource_init(void)
{
PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_ENABLE;
AlertData alert_data = {
.subsystem = 7,
.componentId = 1,
.deviceId = 0,
};
TEST_ASSERT_EQUAL(
POST_DEV_NO_CFG_REQ,
PWRSRC_fxnTable.cb_init(&gbc_pwr_powerSource, NULL, &alert_data));
}
void test_ocmp_powerSource_probe(void)
{
POSTData postData;
PWR_GpioConfig[OC_EC_PWR_PRSNT_SOLAR_AUX] = OCGPIO_CFG_OUTPUT;
PWR_GpioConfig[OC_EC_PWR_PRSNT_POE] = OCGPIO_CFG_OUTPUT;
SX1509_regs[SX1509_REG_SENSE_HIGH_B] = OCGPIO_CFG_INPUT;
TEST_ASSERT_EQUAL(POST_DEV_NOSTATUS, PWRSRC_fxnTable.cb_probe(
&gbc_pwr_powerSource, &postData));
TEST_ASSERT_EQUAL(OCGPIO_CFG_INPUT,
PWR_GpioConfig[OC_EC_PWR_PRSNT_SOLAR_AUX]);
TEST_ASSERT_EQUAL(OCGPIO_CFG_INPUT, PWR_GpioConfig[OC_EC_PWR_PRSNT_POE]);
TEST_ASSERT_EQUAL(OCGPIO_CFG_OUTPUT, SX1509_regs[SX1509_REG_SENSE_HIGH_B]);
}
void test_ocmp_powerSource_get_status_poeAvailable(void)
{
/* POE State available */
uint8_t powerStatus = PWR_SRC_NOT_AVAILABLE;
PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_ENABLE;
PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_DISABLE;
SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_EXT_BAT_DISABLE_FIRST_BYTE;
SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_EXT_BAT_DISABLE_SECOND_BYTE;
pwr_source_init();
pwr_get_source_info(&gbc_pwr_powerSource);
TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status(
&gbc_pwr_powerSource, PWR_STAT_POE_AVAILABILITY,
&powerStatus));
TEST_ASSERT_EQUAL(PWR_SRC_ACTIVE_AVAILABLE, powerStatus);
/* POE State Not Available */
powerStatus = PWR_SRC_ACTIVE_AVAILABLE;
PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_DISABLE;
pwr_source_init();
pwr_get_source_info(&gbc_pwr_powerSource);
TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status(
&gbc_pwr_powerSource, PWR_STAT_POE_AVAILABILITY,
&powerStatus));
TEST_ASSERT_EQUAL(PWR_SRC_NOT_AVAILABLE, powerStatus);
}
void test_ocmp_powerSource_get_status_poeAccessible(void)
{
/* POE State Accessible */
uint8_t powerStatus = PWR_SRC_NOT_AVAILABLE;
PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_ENABLE;
PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_DISABLE;
SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_EXT_BAT_DISABLE_FIRST_BYTE;
SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_EXT_BAT_DISABLE_SECOND_BYTE;
pwr_source_init();
pwr_get_source_info(&gbc_pwr_powerSource);
TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status(
&gbc_pwr_powerSource,
PWR_STAT_POE_ACCESSIBILITY, &powerStatus));
TEST_ASSERT_EQUAL(PWR_SRC_ACTIVE_AVAILABLE, powerStatus);
/* POE State Not Accessible */
powerStatus = PWR_SRC_ACTIVE_AVAILABLE;
PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_DISABLE;
pwr_source_init();
pwr_get_source_info(&gbc_pwr_powerSource);
TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status(
&gbc_pwr_powerSource,
PWR_STAT_POE_ACCESSIBILITY, &powerStatus));
TEST_ASSERT_EQUAL(PWR_SRC_NOT_AVAILABLE, powerStatus);
}
void test_ocmp_powerSource_get_status_solaravailable(void)
{
/* Solar State Available */
uint8_t powerStatus = PWR_SRC_NOT_AVAILABLE;
PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_DISABLE;
PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_ENABLE;
SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_EXT_BAT_DISABLE_FIRST_BYTE;
SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_EXT_BAT_DISABLE_SECOND_BYTE;
pwr_source_init();
pwr_get_source_info(&gbc_pwr_powerSource);
TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status(
&gbc_pwr_powerSource,
PWR_STAT_SOLAR_AVAILABILITY, &powerStatus));
TEST_ASSERT_EQUAL(PWR_SRC_ACTIVE_AVAILABLE, powerStatus);
/* Solar State Not Available */
powerStatus = PWR_SRC_ACTIVE_AVAILABLE;
PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_DISABLE;
pwr_source_init();
pwr_get_source_info(&gbc_pwr_powerSource);
TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status(
&gbc_pwr_powerSource,
PWR_STAT_SOLAR_AVAILABILITY, &powerStatus));
TEST_ASSERT_EQUAL(PWR_SRC_NOT_AVAILABLE, powerStatus);
}
void test_ocmp_powerSource_get_status_solaraccessible(void)
{
/* Solar State Accessible */
uint8_t powerStatus = PWR_SRC_NOT_AVAILABLE;
PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_DISABLE;
PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_ENABLE;
SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_EXT_BAT_DISABLE_FIRST_BYTE;
SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_EXT_BAT_DISABLE_SECOND_BYTE;
pwr_source_init();
pwr_get_source_info(&gbc_pwr_powerSource);
TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status(
&gbc_pwr_powerSource,
PWR_STAT_SOLAR_ACCESSIBILITY, &powerStatus));
TEST_ASSERT_EQUAL(PWR_SRC_ACTIVE_AVAILABLE, powerStatus);
/* Solar State Not Accessible */
powerStatus = PWR_SRC_ACTIVE_AVAILABLE;
PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_DISABLE;
pwr_source_init();
pwr_get_source_info(&gbc_pwr_powerSource);
TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status(
&gbc_pwr_powerSource,
PWR_STAT_SOLAR_ACCESSIBILITY, &powerStatus));
TEST_ASSERT_EQUAL(PWR_SRC_NOT_AVAILABLE, powerStatus);
}
void test_ocmp_powerSource_get_status_extavailable(void)
{
/* EXT Battery Available */
uint8_t powerStatus = PWR_SRC_NOT_AVAILABLE;
PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_DISABLE;
PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_DISABLE;
SX1509_regs[SX1509_REG_DATA_B] = PWR_EXT_BAT_ENABLE_FIRST_BYTE;
SX1509_regs[SX1509_REG_DATA_A] = PWR_EXT_BAT_ENABLE_SECOND_BYTE;
pwr_source_init();
pwr_get_source_info(&gbc_pwr_powerSource);
TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status(
&gbc_pwr_powerSource,
PWR_STAT_EXTBATT_AVAILABILITY, &powerStatus));
TEST_ASSERT_EQUAL(PWR_SRC_ACTIVE_AVAILABLE, powerStatus);
/* EXT Battery Not Available */
powerStatus = PWR_SRC_ACTIVE_AVAILABLE;
SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_EXT_BAT_DISABLE_FIRST_BYTE;
SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_EXT_BAT_DISABLE_SECOND_BYTE;
pwr_source_init();
pwr_get_source_info(&gbc_pwr_powerSource);
TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status(
&gbc_pwr_powerSource,
PWR_STAT_EXTBATT_AVAILABILITY, &powerStatus));
TEST_ASSERT_EQUAL(PWR_SRC_NOT_AVAILABLE, powerStatus);
}
void test_ocmp_powerSource_get_status_extaccessible(void)
{
/* EXT Battery Accessible */
uint8_t powerStatus = PWR_SRC_NOT_AVAILABLE;
PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_DISABLE;
PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_DISABLE;
SX1509_regs[SX1509_REG_DATA_B] = PWR_EXT_BAT_ENABLE_FIRST_BYTE;
SX1509_regs[SX1509_REG_DATA_A] = PWR_EXT_BAT_ENABLE_SECOND_BYTE;
pwr_source_init();
pwr_get_source_info(&gbc_pwr_powerSource);
TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status(
&gbc_pwr_powerSource,
PWR_STAT_EXTBATT_ACCESSIBILITY, &powerStatus));
TEST_ASSERT_EQUAL(PWR_SRC_ACTIVE_AVAILABLE, powerStatus);
/* EXT Battery Not Accessible */
powerStatus = PWR_SRC_ACTIVE_AVAILABLE;
SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_EXT_BAT_DISABLE_FIRST_BYTE;
SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_EXT_BAT_DISABLE_SECOND_BYTE;
pwr_source_init();
pwr_get_source_info(&gbc_pwr_powerSource);
TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status(
&gbc_pwr_powerSource,
PWR_STAT_EXTBATT_ACCESSIBILITY, &powerStatus));
TEST_ASSERT_EQUAL(PWR_SRC_NOT_AVAILABLE, powerStatus);
}
void test_ocmp_powerSource_get_status_intavailable(void)
{
/* Int Battery Available */
uint8_t powerStatus = PWR_SRC_NOT_AVAILABLE;
PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_DISABLE;
PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_DISABLE;
SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_BAT_ENABLE_FIRST_BYTE;
SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_BAT_ENABLE_SECOND_BYTE;
pwr_source_init();
pwr_get_source_info(&gbc_pwr_powerSource);
TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status(
&gbc_pwr_powerSource,
PWR_STAT_INTBATT_AVAILABILITY, &powerStatus));
TEST_ASSERT_EQUAL(PWR_SRC_ACTIVE_AVAILABLE, powerStatus);
/* Int Battery Not Available */
powerStatus = PWR_SRC_ACTIVE_AVAILABLE;
SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_EXT_BAT_DISABLE_FIRST_BYTE;
SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_EXT_BAT_DISABLE_SECOND_BYTE;
pwr_source_init();
pwr_get_source_info(&gbc_pwr_powerSource);
TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status(
&gbc_pwr_powerSource,
PWR_STAT_INTBATT_AVAILABILITY, &powerStatus));
TEST_ASSERT_EQUAL(PWR_SRC_NOT_AVAILABLE, powerStatus);
}
void test_ocmp_powerSource_get_status_intaccessible(void)
{
uint8_t powerStatus = PWR_SRC_NOT_AVAILABLE;
/* Int Battery Not Accessible */
PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_DISABLE;
PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_DISABLE;
SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_BAT_ENABLE_FIRST_BYTE;
SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_BAT_ENABLE_SECOND_BYTE;
pwr_source_init();
pwr_get_source_info(&gbc_pwr_powerSource);
TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status(
&gbc_pwr_powerSource,
PWR_STAT_INTBATT_ACCESSIBILITY, &powerStatus));
TEST_ASSERT_EQUAL(PWR_SRC_ACTIVE_AVAILABLE, powerStatus);
/* Int Battery Not Accessible */
powerStatus = PWR_SRC_ACTIVE_AVAILABLE;
SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_EXT_BAT_DISABLE_FIRST_BYTE;
SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_EXT_BAT_DISABLE_SECOND_BYTE;
pwr_source_init();
pwr_get_source_info(&gbc_pwr_powerSource);
TEST_ASSERT_EQUAL(true, PWRSRC_fxnTable.cb_get_status(
&gbc_pwr_powerSource,
PWR_STAT_INTBATT_ACCESSIBILITY, &powerStatus));
TEST_ASSERT_EQUAL(PWR_SRC_NOT_AVAILABLE, powerStatus);
}
void test_ocmp_powerSource_get_status_invalid_param(void)
{
uint8_t powerStatus = PWR_SRC_ACTIVE_AVAILABLE;
/* Invalid Param Test */
PWR_GpioPins[OC_EC_PWR_PRSNT_POE] = PWR_STATE_DISABLE;
PWR_GpioPins[OC_EC_PWR_PRSNT_SOLAR_AUX] = PWR_STATE_DISABLE;
SX1509_regs[SX1509_REG_DATA_B] = PWR_INT_BAT_ENABLE_FIRST_BYTE;
SX1509_regs[SX1509_REG_DATA_A] = PWR_INT_BAT_ENABLE_SECOND_BYTE;
pwr_source_init();
pwr_get_source_info(&gbc_pwr_powerSource);
TEST_ASSERT_EQUAL(
true, PWRSRC_fxnTable.cb_get_status(
&gbc_pwr_powerSource, PWR_STATE_INVALID_PARAM, &powerStatus));
TEST_ASSERT_EQUAL(PWR_SRC_NOT_AVAILABLE, powerStatus);
}

View File

@@ -0,0 +1,26 @@
#!/bin/bash
#
# Copyright (c) 2018-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
# Get all files that are different from master and only lint those.
fileList=`git --no-pager diff --name-only HEAD origin/master ./firmware/ec | grep ".\.c$\|.\.h$"`
for f in $fileList; do
clang-format -style=file -i ${f}
done
echo "Linting the following files:"
echo $fileList
git diff > clang_format.patch
# Delete if 0 size and exit with 0
if [ ! -s clang_format.patch ]
then
exit 0
fi
# There were lint issues and should exit with error
exit 1

View File

@@ -0,0 +1,83 @@
#!/usr/bin/env python3
#
# Copyright (c) 2018-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
""""
Script to convert lcov generated coverage data to Jenkins readable Cobertura
XML coverage formatted data.
"""
import argparse
import glob
import os
import sys
from lcov_cobertura import LcovCobertura
def main(args):
# Auto set arguments if none were provided
# If no sourcefile was provided, find the test-coverage.info file.
# This assumes that the first file found is the desired one, so if multiple
# exist then the sourceFile must be specified on the command line.
if not args.sourceFile:
f = glob.glob('**/test-coverage.info', recursive=True)
if f:
sourceFile = f[0]
else:
sys.exit("No lcov output file found below current directory.")
else:
sourceFile = args.sourceFile
# If no output file was provided, then place it in the same directory as
# the source file.
if not args.outFile:
outFile = os.path.dirname(sourceFile) + '/test-coverage.xml'
else:
outFile = args.outFile
# Read all the data from the lcov output file
with open(sourceFile) as fr:
data = fr.read()
# Create a converter and convert coverage data
converter = LcovCobertura(data)
res = converter.convert()
# Write all output data to the destination file.
with open(outFile, 'w') as fw:
fw.write(res)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
# lcov data source file
parser.add_argument(
'-i',
dest='sourceFile',
action='store',
default='',
type=str,
help='lcov data file to extract coverage information from. If not \
provided, will recursively search from cwd for test-coverage.info\
to use. If it finds multiple, will use the first one found',
)
# Output file name
parser.add_argument(
'-o',
dest='outFile',
action='store',
default='',
type=str,
help='Name of file to write xml coverage data to. If not provided, will\
default to test-coverage.xml in the same directory as sourceFile',
)
main(parser.parse_args())