Fix programs/bpf bpf_c and bpf_rust features to work independently
`cargo test --features="bpf_c"` fails to compile without this fix.
This commit is contained in:
parent
6e57a8f8a1
commit
09e26c7d29
|
@ -3,26 +3,61 @@
|
|||
#[macro_use]
|
||||
extern crate solana_bpf_loader_program;
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
use {
|
||||
itertools::izip,
|
||||
log::{log_enabled, trace, Level::Trace},
|
||||
solana_account_decoder::parse_bpf_loader::{
|
||||
parse_bpf_upgradeable_loader, BpfUpgradeableLoaderAccountType,
|
||||
},
|
||||
solana_bpf_rust_invoke::instructions::*,
|
||||
solana_bpf_rust_realloc::instructions::*,
|
||||
solana_bpf_rust_realloc_invoke::instructions::*,
|
||||
solana_ledger::token_balances::collect_token_balances,
|
||||
solana_program_runtime::{compute_budget::ComputeBudget, timings::ExecuteTimings},
|
||||
solana_runtime::{
|
||||
bank::{
|
||||
DurableNonceFee, TransactionBalancesSet, TransactionExecutionDetails,
|
||||
TransactionExecutionResult, TransactionResults,
|
||||
},
|
||||
loader_utils::{
|
||||
load_buffer_account, load_upgradeable_program, set_upgrade_authority, upgrade_program,
|
||||
},
|
||||
},
|
||||
solana_sdk::{
|
||||
account::{ReadableAccount, WritableAccount},
|
||||
account_utils::StateMut,
|
||||
bpf_loader_upgradeable,
|
||||
clock::MAX_PROCESSING_AGE,
|
||||
compute_budget::ComputeBudgetInstruction,
|
||||
entrypoint::MAX_PERMITTED_DATA_INCREASE,
|
||||
feature_set::FeatureSet,
|
||||
fee::FeeStructure,
|
||||
fee_calculator::FeeRateGovernor,
|
||||
instruction::CompiledInstruction,
|
||||
loader_instruction,
|
||||
message::{v0::LoadedAddresses, SanitizedMessage},
|
||||
rent::Rent,
|
||||
signature::keypair_from_seed,
|
||||
stake,
|
||||
system_instruction::{self, MAX_PERMITTED_DATA_LENGTH},
|
||||
sysvar::{self, clock, rent},
|
||||
transaction::VersionedTransaction,
|
||||
},
|
||||
solana_transaction_status::{
|
||||
ConfirmedTransactionWithStatusMeta, InnerInstructions, TransactionStatusMeta,
|
||||
TransactionWithStatusMeta, VersionedTransactionWithStatusMeta,
|
||||
},
|
||||
std::{collections::HashMap, str::FromStr},
|
||||
};
|
||||
use {
|
||||
log::{log_enabled, trace, Level::Trace},
|
||||
solana_bpf_loader_program::{
|
||||
create_vm,
|
||||
serialization::{deserialize_parameters, serialize_parameters},
|
||||
syscalls::register_syscalls,
|
||||
BpfError, ThisInstructionMeter,
|
||||
},
|
||||
solana_bpf_rust_invoke::instructions::*,
|
||||
solana_bpf_rust_realloc::instructions::*,
|
||||
solana_bpf_rust_realloc_invoke::instructions::*,
|
||||
solana_ledger::token_balances::collect_token_balances,
|
||||
solana_program_runtime::{
|
||||
compute_budget::ComputeBudget, invoke_context::with_mock_invoke_context,
|
||||
timings::ExecuteTimings,
|
||||
},
|
||||
solana_program_runtime::invoke_context::with_mock_invoke_context,
|
||||
solana_rbpf::{
|
||||
elf::Executable,
|
||||
static_analysis::Analysis,
|
||||
|
@ -30,45 +65,24 @@ use {
|
|||
vm::{Config, Tracer, VerifiedExecutable},
|
||||
},
|
||||
solana_runtime::{
|
||||
bank::{
|
||||
Bank, DurableNonceFee, TransactionBalancesSet, TransactionExecutionDetails,
|
||||
TransactionExecutionResult, TransactionResults,
|
||||
},
|
||||
bank::Bank,
|
||||
bank_client::BankClient,
|
||||
genesis_utils::{create_genesis_config, GenesisConfigInfo},
|
||||
loader_utils::{
|
||||
load_buffer_account, load_program, load_upgradeable_program, set_upgrade_authority,
|
||||
upgrade_program,
|
||||
},
|
||||
loader_utils::load_program,
|
||||
},
|
||||
solana_sdk::{
|
||||
account::{AccountSharedData, ReadableAccount, WritableAccount},
|
||||
account_utils::StateMut,
|
||||
bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable,
|
||||
account::AccountSharedData,
|
||||
bpf_loader, bpf_loader_deprecated,
|
||||
client::SyncClient,
|
||||
clock::MAX_PROCESSING_AGE,
|
||||
compute_budget::ComputeBudgetInstruction,
|
||||
entrypoint::{MAX_PERMITTED_DATA_INCREASE, SUCCESS},
|
||||
feature_set::FeatureSet,
|
||||
fee::FeeStructure,
|
||||
fee_calculator::FeeRateGovernor,
|
||||
instruction::{AccountMeta, CompiledInstruction, Instruction, InstructionError},
|
||||
loader_instruction,
|
||||
message::{v0::LoadedAddresses, Message, SanitizedMessage},
|
||||
entrypoint::SUCCESS,
|
||||
instruction::{AccountMeta, Instruction, InstructionError},
|
||||
message::Message,
|
||||
pubkey::Pubkey,
|
||||
rent::Rent,
|
||||
signature::{keypair_from_seed, Keypair, Signer},
|
||||
stake,
|
||||
system_instruction::{self, MAX_PERMITTED_DATA_LENGTH},
|
||||
signature::{Keypair, Signer},
|
||||
system_program,
|
||||
sysvar::{self, clock, rent},
|
||||
transaction::{SanitizedTransaction, Transaction, TransactionError, VersionedTransaction},
|
||||
transaction::{SanitizedTransaction, Transaction, TransactionError},
|
||||
},
|
||||
solana_transaction_status::{
|
||||
ConfirmedTransactionWithStatusMeta, InnerInstructions, TransactionStatusMeta,
|
||||
TransactionWithStatusMeta, VersionedTransactionWithStatusMeta,
|
||||
},
|
||||
std::{collections::HashMap, env, fs::File, io::Read, path::PathBuf, str::FromStr, sync::Arc},
|
||||
std::{env, fs::File, io::Read, path::PathBuf, sync::Arc},
|
||||
};
|
||||
|
||||
/// BPF program file extension
|
||||
|
@ -130,6 +144,7 @@ fn write_bpf_program(
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn load_upgradeable_bpf_program(
|
||||
bank_client: &BankClient,
|
||||
payer_keypair: &Keypair,
|
||||
|
@ -154,6 +169,7 @@ fn load_upgradeable_bpf_program(
|
|||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn load_upgradeable_buffer(
|
||||
bank_client: &BankClient,
|
||||
payer_keypair: &Keypair,
|
||||
|
@ -176,6 +192,7 @@ fn load_upgradeable_buffer(
|
|||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn upgrade_bpf_program(
|
||||
bank_client: &BankClient,
|
||||
payer_keypair: &Keypair,
|
||||
|
@ -344,6 +361,7 @@ fn run_program(name: &str) -> u64 {
|
|||
})
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn process_transaction_and_record_inner(
|
||||
bank: &Bank,
|
||||
tx: Transaction,
|
||||
|
@ -386,6 +404,7 @@ fn process_transaction_and_record_inner(
|
|||
(result, inner_instructions, log_messages)
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn execute_transactions(
|
||||
bank: &Bank,
|
||||
txs: Vec<Transaction>,
|
||||
|
@ -634,6 +653,7 @@ fn test_program_bpf_loader_deprecated() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_sol_alloc_free_no_longer_deployable() {
|
||||
solana_logger::setup();
|
||||
|
||||
|
@ -719,6 +739,7 @@ fn test_sol_alloc_free_no_longer_deployable() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_bpf_duplicate_accounts() {
|
||||
solana_logger::setup();
|
||||
|
||||
|
@ -819,6 +840,7 @@ fn test_program_bpf_duplicate_accounts() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_bpf_error_handling() {
|
||||
solana_logger::setup();
|
||||
|
||||
|
@ -975,6 +997,7 @@ fn test_return_data_and_log_data_syscall() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_bpf_invoke_sanity() {
|
||||
solana_logger::setup();
|
||||
|
||||
|
@ -1397,8 +1420,8 @@ fn test_program_bpf_invoke_sanity() {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_bpf_program_id_spoofing() {
|
||||
let GenesisConfigInfo {
|
||||
genesis_config,
|
||||
|
@ -1450,8 +1473,8 @@ fn test_program_bpf_program_id_spoofing() {
|
|||
assert_eq!(0, bank.get_balance(&to_pubkey));
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_bpf_caller_has_access_to_cpi_program() {
|
||||
let GenesisConfigInfo {
|
||||
genesis_config,
|
||||
|
@ -1488,8 +1511,8 @@ fn test_program_bpf_caller_has_access_to_cpi_program() {
|
|||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_bpf_ro_modify() {
|
||||
solana_logger::setup();
|
||||
|
||||
|
@ -1545,8 +1568,8 @@ fn test_program_bpf_ro_modify() {
|
|||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_bpf_call_depth() {
|
||||
solana_logger::setup();
|
||||
|
||||
|
@ -1580,8 +1603,8 @@ fn test_program_bpf_call_depth() {
|
|||
assert!(result.is_err());
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_bpf_compute_budget() {
|
||||
solana_logger::setup();
|
||||
|
||||
|
@ -1678,8 +1701,8 @@ fn assert_instruction_count() {
|
|||
assert!(passed);
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "bpf_rust"))]
|
||||
#[test]
|
||||
#[cfg(any(feature = "bpf_rust"))]
|
||||
fn test_program_bpf_instruction_introspection() {
|
||||
solana_logger::setup();
|
||||
|
||||
|
@ -1739,8 +1762,8 @@ fn test_program_bpf_instruction_introspection() {
|
|||
assert!(bank.get_account(&sysvar::instructions::id()).is_none());
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_bpf_test_use_latest_executor() {
|
||||
solana_logger::setup();
|
||||
|
||||
|
@ -1834,8 +1857,8 @@ fn test_program_bpf_test_use_latest_executor() {
|
|||
}
|
||||
|
||||
#[ignore] // Invoking BPF loaders from CPI not allowed
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_bpf_test_use_latest_executor2() {
|
||||
solana_logger::setup();
|
||||
|
||||
|
@ -1964,8 +1987,8 @@ fn test_program_bpf_test_use_latest_executor2() {
|
|||
.is_ok());
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_bpf_upgrade() {
|
||||
solana_logger::setup();
|
||||
|
||||
|
@ -2052,8 +2075,8 @@ fn test_program_bpf_upgrade() {
|
|||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_bpf_upgrade_and_invoke_in_same_tx() {
|
||||
solana_logger::setup();
|
||||
|
||||
|
@ -2126,8 +2149,8 @@ fn test_program_bpf_upgrade_and_invoke_in_same_tx() {
|
|||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_bpf_invoke_upgradeable_via_cpi() {
|
||||
solana_logger::setup();
|
||||
|
||||
|
@ -2297,8 +2320,8 @@ fn test_program_bpf_c_dup() {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_bpf_upgrade_via_cpi() {
|
||||
solana_logger::setup();
|
||||
|
||||
|
@ -2410,8 +2433,8 @@ fn test_program_bpf_upgrade_via_cpi() {
|
|||
assert_ne!(programdata, original_programdata);
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_bpf_upgrade_self_via_cpi() {
|
||||
solana_logger::setup();
|
||||
|
||||
|
@ -2499,8 +2522,8 @@ fn test_program_bpf_upgrade_self_via_cpi() {
|
|||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_bpf_set_upgrade_authority_via_cpi() {
|
||||
solana_logger::setup();
|
||||
|
||||
|
@ -2587,8 +2610,8 @@ fn test_program_bpf_set_upgrade_authority_via_cpi() {
|
|||
assert_eq!(Some(new_upgrade_authority_key), upgrade_authority_key);
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_upgradeable_locks() {
|
||||
fn setup_program_upgradeable_locks(
|
||||
payer_keypair: &Keypair,
|
||||
|
@ -2719,8 +2742,8 @@ fn test_program_upgradeable_locks() {
|
|||
assert_eq!(results2[1], Err(TransactionError::AccountInUse));
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_bpf_finalize() {
|
||||
solana_logger::setup();
|
||||
|
||||
|
@ -2781,8 +2804,8 @@ fn test_program_bpf_finalize() {
|
|||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_bpf_ro_account_modify() {
|
||||
solana_logger::setup();
|
||||
|
||||
|
@ -2843,8 +2866,8 @@ fn test_program_bpf_ro_account_modify() {
|
|||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_bpf_realloc() {
|
||||
solana_logger::setup();
|
||||
|
||||
|
@ -3843,8 +3866,8 @@ fn test_get_minimum_delegation() {
|
|||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
#[test]
|
||||
#[cfg(feature = "bpf_rust")]
|
||||
fn test_program_bpf_inner_instruction_alignment_checks() {
|
||||
solana_logger::setup();
|
||||
|
||||
|
|
Loading…
Reference in New Issue