Skip to content

Commit

Permalink
Merge pull request #14 from Myoldmopar/Toward940
Browse files Browse the repository at this point in the history
Toward 9.4.0
  • Loading branch information
Myoldmopar authored Aug 22, 2020
2 parents 4648385 + 92b2c03 commit e0c2d9b
Show file tree
Hide file tree
Showing 11 changed files with 196 additions and 115 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
script: python3 setup.py run
- os: osx
name: Mac E+ Tests
osx_image: xcode11.2
osx_image: xcode11.4
before_script: pip3 install -r requirements.txt
script: python3 setup.py run
- os: windows
Expand Down
4 changes: 2 additions & 2 deletions ep_testing/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ class TestConfiguration:

def __init__(self):
self.this_version = '9.4'
self.tag_this_version = 'v9.4.0-TestSymlinkFix2'
self.tag_this_version = 'v9.4.0-IOFreeze-RC1'
self.last_version = '9.3'
self.tag_last_version = 'v9.3.0'

# If this is turned on, it expects to find an asset named target_file_name in the download_dir
self.skip_download = True
self.skipped_download_file = '/var/folders/1b/glc4bp3s2s52xb8vdgsj4qsw5dydhj/T/tmpy9_mlk48/ep.tar.gz'
self.skipped_download_file = '/tmp/ep.tar.gz'

# But if we are on Travis, we override it to always download a new asset
if os.environ.get('TRAVIS'):
Expand Down
1 change: 1 addition & 0 deletions ep_testing/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def __init__(self, config: TestConfiguration, announce: callable = None):
this_platform = platform.system()
extract_dir_name = 'ep_package'
self.extract_path = os.path.join(config.download_dir, extract_dir_name)
# need to adapt this to the new filename structure when we get there
if this_platform == 'Linux':
self.asset_pattern = 'Linux-x86_64.tar.gz'
target_file_name = 'ep.tar.gz'
Expand Down
140 changes: 28 additions & 112 deletions ep_testing/tests/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
from ep_testing.tests.base import BaseTest


def api_resource_dir() -> str:
this_file_path = os.path.realpath(__file__)
this_directory = os.path.dirname(this_file_path)
templates_dir = os.path.join(this_directory, 'api_templates')
return templates_dir


def my_check_call(verbose: bool, command_line: List[str], **kwargs) -> None:
if verbose:
check_call(command_line, **kwargs)
Expand All @@ -26,17 +33,9 @@ def _api_script_content(install_root: str) -> str:
pass
else: # windows
install_root = install_root.replace('\\', '\\\\')
return """
#!/usr/bin/env python3
import sys
sys.path.insert(0, '%s')
from pyenergyplus.api import EnergyPlusAPI
api = EnergyPlusAPI()
glycol = api.functional.glycol(u"water")
for t in [5.0, 15.0, 25.0]:
cp = glycol.specific_heat(t)
rho = glycol.density(t)
""" % install_root
template_file = os.path.join(api_resource_dir(), 'python_link.py')
template = open(template_file).read()
return template % install_root

def run(self, install_root: str, verbose: bool, kwargs: dict):
self.verbose = verbose
Expand Down Expand Up @@ -90,16 +89,9 @@ def name(self):

@staticmethod
def _api_fixup_content() -> str:
return """
include(GetPrerequisites)
get_prerequisites(${TARGET_PATH} PR 0 0 "" "")
foreach(P IN LISTS PR)
string(FIND ${P} "energyplus" EPFOUND)
if (NOT EPFOUND EQUAL -1)
execute_process(COMMAND install_name_tool -change ${P} "${DLL_PATH}" ${TARGET_PATH})
endif()
endforeach()
"""
template_file = os.path.join(api_resource_dir(), 'eager_cpp_fixup.txt')
template = open(template_file).read()
return template

def _api_cmakelists_content(self, install_path: str) -> str:
if platform.system() == 'Linux':
Expand All @@ -109,47 +101,18 @@ def _api_cmakelists_content(self, install_path: str) -> str:
else: # windows
lib_file_name = 'energyplusapi.lib'
install_path = install_path.replace('\\', '\\\\')
return """
cmake_minimum_required(VERSION 3.10)
project({TARGET_NAME})
include_directories("{EPLUS_INSTALL_NO_SLASH}/include")
add_executable({TARGET_NAME} {SOURCE_FILE})
set(DLL_PATH "{EPLUS_INSTALL_NO_SLASH}/{LIB_FILE_NAME}")
target_link_libraries({TARGET_NAME} ${{DLL_PATH}})
if (APPLE)
add_custom_command(
TARGET TestCAPIAccess POST_BUILD
COMMAND
${{CMAKE_COMMAND}}
-DDLL_PATH=${{DLL_PATH}} -DTARGET_PATH=$<TARGET_FILE:{TARGET_NAME}>
-P "${{CMAKE_SOURCE_DIR}}/fixup.cmake"
DEPENDS "${{CMAKE_SOURCE_DIR}}/fixup.cmake"
)
endif()
""".format(
template_file = os.path.join(api_resource_dir(), 'eager_cpp_cmakelists.txt')
template = open(template_file).read()
return template.format(
EPLUS_INSTALL_NO_SLASH=install_path, LIB_FILE_NAME=lib_file_name,
TARGET_NAME=self.target_name, SOURCE_FILE=self.source_file_name
)

@staticmethod
def _api_script_content() -> str:
return """
#include <stddef.h>
#include <stdio.h>
#include <EnergyPlus/api/func.h>
int main() {
initializeFunctionalAPI();
Glycol glycol = NULL;
glycol = glycolNew("WatEr");
for (int temp=5; temp<35; temp+=10) {
Real64 thisTemp = (float)temp;
Real64 specificHeat = glycolSpecificHeat(glycol, thisTemp);
printf("Cp = %8.3f\\n", specificHeat);
}
glycolDelete(glycol);
printf("Hello, world!\\n");
}
"""
template_file = os.path.join(api_resource_dir(), 'eager_cpp_source.cpp')
template = open(template_file).read()
return template

def run(self, install_root: str, verbose: bool, kwargs: dict):
self.verbose = verbose
Expand Down Expand Up @@ -193,12 +156,9 @@ def name(self):
return 'Test running an API script against energyplus in C++ but with delayed DLL loading'

def _api_cmakelists_content(self) -> str:
return """
cmake_minimum_required(VERSION 3.10)
project({TARGET_NAME})
add_executable({TARGET_NAME} {SOURCE_FILE})
target_link_libraries({TARGET_NAME} ${{CMAKE_DL_LIBS}})
""".format(TARGET_NAME=self.target_name, SOURCE_FILE=self.source_file_name)
template_file = os.path.join(api_resource_dir(), 'delayed_cpp_cmakelists.txt')
template = open(template_file).read()
return template.format(TARGET_NAME=self.target_name, SOURCE_FILE=self.source_file_name)

@staticmethod
def _api_script_content(install_path: str) -> str:
Expand All @@ -208,61 +168,17 @@ def _api_script_content(install_path: str) -> str:
lib_file_name = '/libenergyplusapi.dylib'
else: # windows
raise EPTestingException('Dont call TestCAPIDelayedAccess._api_script_content for Windows')
return """
#include <iostream>
#include <dlfcn.h>
int main() {
std::cout << "Opening eplus shared library...\\n";
void* handle = dlopen("{EPLUS_INSTALL_NO_SLASH}{LIB_FILE_NAME}", RTLD_LAZY);
if (!handle) {
std::cerr << "Cannot open library: \\n";
return 1;
}
dlerror(); // reset errors
std::cout << "Loading init function symbol...\\n";
typedef void (*init_t)();
init_t init = (init_t) dlsym(handle, "initializeFunctionalAPI");
const char *dlsym_error = dlerror();
if (dlsym_error) {
std::cerr << "Cannot load symbol 'initializeFunctionalAPI': \\n";
dlclose(handle);
return 1;
}
std::cout << "Calling to initialize...\\n";
init();
std::cout << "Closing library...\\n";
dlclose(handle);
}
""".replace('{EPLUS_INSTALL_NO_SLASH}', install_path).replace('{LIB_FILE_NAME}', lib_file_name)
template_file = os.path.join(api_resource_dir(), 'delayed_cpp_source_linux_mac.cpp')
template = open(template_file).read()
return template.replace('{EPLUS_INSTALL_NO_SLASH}', install_path).replace('{LIB_FILE_NAME}', lib_file_name)

@staticmethod
def _api_script_content_windows(install_path: str) -> str:
lib_file_name = '\\\\energyplusapi.dll'
install_path = install_path.replace('\\', '\\\\')
return """
#include <windows.h>
#include <iostream>
int main() {
std::cout << "Opening eplus shared library...\\n";
HINSTANCE hInst;
hInst = LoadLibrary("{EPLUS_INSTALL_NO_SLASH}{LIB_FILE_NAME}");
if (!hInst) {
std::cerr << "Cannot open library: \\n";
return 1;
}
typedef void (*INITFUNCTYPE)();
INITFUNCTYPE init;
init = (INITFUNCTYPE)GetProcAddress((HINSTANCE)hInst, "initializeFunctionalAPI");
if (!init) {
std::cerr << "Cannot get function \\n";
return 1;
}
std::cout << "Calling to initialize\\n";
init();
std::cout << "Closing library\\n";
FreeLibrary((HINSTANCE)hInst);
}
""".replace('{EPLUS_INSTALL_NO_SLASH}', install_path).replace('{LIB_FILE_NAME}', lib_file_name)
template_file = os.path.join(api_resource_dir(), 'delayed_cpp_source_windows.cpp')
template = open(template_file).read()
return template.replace('{EPLUS_INSTALL_NO_SLASH}', install_path).replace('{LIB_FILE_NAME}', lib_file_name)

def run(self, install_root: str, verbose: bool, kwargs: dict):
self.verbose = verbose
Expand Down
4 changes: 4 additions & 0 deletions ep_testing/tests/api_templates/delayed_cpp_cmakelists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cmake_minimum_required(VERSION 3.10)
project({TARGET_NAME})
add_executable({TARGET_NAME} {SOURCE_FILE})
target_link_libraries({TARGET_NAME} ${{CMAKE_DL_LIBS}})
87 changes: 87 additions & 0 deletions ep_testing/tests/api_templates/delayed_cpp_source_linux_mac.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include <cassert>
#include <iostream>
#include <dlfcn.h>
int main() {
const char *dlsym_error;
std::cout << "Opening eplus shared library...\n";
void* handle = dlopen("{EPLUS_INSTALL_NO_SLASH}{LIB_FILE_NAME}", RTLD_LAZY);
if (!handle) {
std::cerr << "Cannot open library: \n";
return 1;
}
dlerror(); // resets errors
//
std::cout << "Getting a new state instance...\n";
typedef void *(*fNewState)();
auto stateNew = (fNewState) dlsym(handle, "stateNew");
dlsym_error = dlerror();
if (dlsym_error) {
std::cerr << "Cannot load symbol stateNew\n";
dlclose(handle);
return 1;
}
auto state = stateNew();
dlsym_error = dlerror();
if (dlsym_error) {
std::cerr << "Cannot instantiate a new state from stateNew\n";
dlclose(handle);
return 1;
}
//
std::cout << "Calling to initialize...\n";
typedef void (*init_t)(void *);
auto init = (init_t) dlsym(handle, "initializeFunctionalAPI");
dlsym_error = dlerror();
if (dlsym_error) {
std::cerr << "Cannot load symbol 'initializeFunctionalAPI': \n";
dlclose(handle);
return 1;
}
init(state);
dlsym_error = dlerror();
if (dlsym_error) {
std::cerr << "Could not call initialize function \n";
dlclose(handle);
return 1;
}
//
std::cout << "Getting a new Glycol instance...\n";
typedef void* (*newGly)(void *, const char *);
auto thisNewGly = (newGly) dlsym(handle, "glycolNew");
dlsym_error = dlerror();
if (dlsym_error) {
std::cerr << "Cannot load symbol 'glycolNew': \n";
dlclose(handle);
return 1;
}
auto glycolInstance = thisNewGly(state, "water");
dlsym_error = dlerror();
if (dlsym_error) {
std::cerr << "Cannot get a new glycol instance via glycolNew': \n";
dlclose(handle);
return 1;
}
//
std::cout << "Calculating Cp at T = 25C...\n";
typedef double(*cp)(void *, void *, double);
auto glycolCp = (cp) dlsym(handle, "glycolSpecificHeat");
dlsym_error = dlerror();
if (dlsym_error) {
std::cerr << "Cannot load symbol 'glycolSpecificHeat': \n";
dlclose(handle);
return 1;
}
auto cpValue = glycolCp(state, glycolInstance, 25);
dlsym_error = dlerror();
if (dlsym_error) {
std::cerr << "Cannot calculate Cp with glycolSpecificHeat': \n";
dlclose(handle);
return 1;
}
//
std::cout << "Calculated Cp = " << cpValue << "\n";
assert(cpValue > 4150);
assert(cpValue < 4200);
std::cout << "Closing library...\n";
dlclose(handle);
}
22 changes: 22 additions & 0 deletions ep_testing/tests/api_templates/delayed_cpp_source_windows.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <windows.h>
#include <iostream>
int main() {
std::cout << "Opening eplus shared library...\\n";
HINSTANCE hInst;
hInst = LoadLibrary("{EPLUS_INSTALL_NO_SLASH}{LIB_FILE_NAME}");
if (!hInst) {
std::cerr << "Cannot open library: \\n";
return 1;
}
typedef void (*INITFUNCTYPE)();
INITFUNCTYPE init;
init = (INITFUNCTYPE)GetProcAddress((HINSTANCE)hInst, "initializeFunctionalAPI");
if (!init) {
std::cerr << "Cannot get function \\n";
return 1;
}
std::cout << "Calling to initialize\\n";
init();
std::cout << "Closing library\\n";
FreeLibrary((HINSTANCE)hInst);
}
16 changes: 16 additions & 0 deletions ep_testing/tests/api_templates/eager_cpp_cmakelists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.10)
project({TARGET_NAME})
include_directories("{EPLUS_INSTALL_NO_SLASH}/include")
add_executable({TARGET_NAME} {SOURCE_FILE})
set(DLL_PATH "{EPLUS_INSTALL_NO_SLASH}/{LIB_FILE_NAME}")
target_link_libraries({TARGET_NAME} ${{DLL_PATH}})
if (APPLE)
add_custom_command(
TARGET TestCAPIAccess POST_BUILD
COMMAND
${{CMAKE_COMMAND}}
-DDLL_PATH=${{DLL_PATH}} -DTARGET_PATH=$<TARGET_FILE:{TARGET_NAME}>
-P "${{CMAKE_SOURCE_DIR}}/fixup.cmake"
DEPENDS "${{CMAKE_SOURCE_DIR}}/fixup.cmake"
)
endif()
8 changes: 8 additions & 0 deletions ep_testing/tests/api_templates/eager_cpp_fixup.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include(GetPrerequisites)
get_prerequisites(${TARGET_PATH} PR 0 0 "" "")
foreach(P IN LISTS PR)
string(FIND ${P} "energyplus" EPFOUND)
if (NOT EPFOUND EQUAL -1)
execute_process(COMMAND install_name_tool -change ${P} "${DLL_PATH}" ${TARGET_PATH})
endif()
endforeach()
17 changes: 17 additions & 0 deletions ep_testing/tests/api_templates/eager_cpp_source.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stddef.h>
#include <stdio.h>
#include <EnergyPlus/api/state.h>
#include <EnergyPlus/api/func.h>
int main() {
EnergyPlusState state = stateNew();
initializeFunctionalAPI(state);
Glycol glycol = NULL;
glycol = glycolNew(state, "WatEr");
for (int temp=5; temp<35; temp+=10) {
Real64 thisTemp = (float)temp;
Real64 specificHeat = glycolSpecificHeat(state, glycol, thisTemp);
printf("Cp = %8.3f\\n", specificHeat);
}
glycolDelete(state, glycol);
printf("Hello, world!\\n");
}
10 changes: 10 additions & 0 deletions ep_testing/tests/api_templates/python_link.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python3
import sys
sys.path.insert(0, '%s')
from pyenergyplus.api import EnergyPlusAPI # noqa: E402
api = EnergyPlusAPI()
state = api.state_manager.new_state()
glycol = api.functional.glycol(state, u"water")
for t in [5.0, 15.0, 25.0]:
cp = glycol.specific_heat(state, t)
rho = glycol.density(state, t)

0 comments on commit e0c2d9b

Please sign in to comment.