Battery management, charging, and testing